Skip to content

Instantly share code, notes, and snippets.

@sidisinsane
Created March 4, 2015 19:39
Show Gist options
  • Save sidisinsane/6d77b537e8c464710b37 to your computer and use it in GitHub Desktop.
Save sidisinsane/6d77b537e8c464710b37 to your computer and use it in GitHub Desktop.
placeholder redirects
########################################################################################
# store requested protocol in %{ENV:protocol} (i always use this...)
########################################################################################
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=protocol:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=protocol:http]
########################################################################################
# placeholder redirects (exclude specific matching redirects!)
########################################################################################
# 1) exclude specific paths matching beneath pattern
RewriteCond %{HTTP_HOST} !^(www.)?domain.tld/old/abc$
RewriteCond %{HTTP_HOST} !^(www.)?domain.tld/old/xyz$
# 2) apply placeholder redirects to matching and not excluded
RewriteCond %{HTTP_HOST} ^(www.)?domain.tld/old/([a-z]+)$
RewriteRule ^(.*)$ %{ENV:protocol}://domain.tld/new/%2 [R=301,L]
# 3) apply specific redirects to paths excluded in 1)
RewriteCond %{HTTP_HOST} ^(www.)?domain.tld/old/abc$
RewriteRule ^(.*)$ %{ENV:protocol}://domain.tld/new/beginning [R=301,L]
RewriteCond %{HTTP_HOST} ^(www.)?domain.tld/old/xyz$
RewriteRule ^(.*)$ %{ENV:protocol}://domain.tld/new/end [R=301,L]
########################################################################################
# internal placeholder redirects, removing everything after matched pattern
########################################################################################
RedirectMatch 301 /old/([a-z]+)/(.*)/ /new/$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment