Skip to content

Instantly share code, notes, and snippets.

@l0neranger
Created January 7, 2015 01:26
Show Gist options
  • Save l0neranger/65109af95daf9555ab98 to your computer and use it in GitHub Desktop.
Save l0neranger/65109af95daf9555ab98 to your computer and use it in GitHub Desktop.
Mod_Rewrite Example
RewriteEngine on
#
# If the request comes in on the domain cname, redirect to domain root
#
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://domain1.com/$1 [L,R=301,NE,NC]
RewriteCond %{HTTP_HOST} ^www\.domain2\.com$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://domain2.com/$1 [L,R=301,NE,NC]
#
# Default Pages if the request comes in on the domain root with no appending url
#
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^/?$ http://domain1.com/url1 [L,R=301,NE,NC]
RewriteCond %{HTTP_HOST} ^domain2\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^/?$ http://domain2.com/url2 [L,R=301,NE,NC]
#
# Legal Requirement wrt domain1 vs domain2 urls
#
RewriteCond %{HTTP_HOST} ^domain2\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/url1$ [NC,OR]
RewriteCond %{REQUEST_URI} ^/url3$ [NC]
RewriteRule ^/?(.*) http://domain2.com/url2 [L,R=301,NE,NC]
RewriteCond %{HTTP_HOST} ^domain1\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/url2$ [NC]
RewriteRule ^/?(.*) http://domain1.com/url1 [L,R=301,NE,NC]
@l0neranger
Copy link
Author

notes,self

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment