.htaccess URL Rewrites


/ Published in: Apache
Save to your folder(s)

This is good for ensuring your domain is always either accessed with or without the www, which is important for SEO. It is also good if you have multiple domains that should resolve to the same site, and can redirect all requests to the main domain.


Copy this code and paste it in your HTML
  1. # This chain of rules will rewrite old-domain, www.old-domain, and new-domain to www.new-domain
  2.  
  3. rewriteCond %{http_host} ^old-domain\.com$ [OR]
  4. rewriteCond %{http_host} ^www.old-domain\.com$ [OR]
  5. rewriteCond %{http_host} ^old-domain\.org$ [OR]
  6. rewriteCond %{http_host} ^www.old-domain\.org$ [OR]
  7. rewriteCond %{http_host} ^new-domain\.com$ [NC]
  8. rewriteRule ^(.*)$ http://www.new-domain.com/$1 [r=301,L]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.