Apache Redirect from *.example.com to example.com

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

Copy this code and paste it in your HTML
  1. #****************************************
  2. # Apache redirect from *.example.com to example.com
  3. #****************************************
  5. RewriteEngine on
  7. #the domain does not match "example.com"
  8. #note that you need the end-of-string character $ or it wouldn't catch something like "example.com.example.com"
  9. RewriteCond %{HTTP_HOST} !^example\.com$
  11. #replace the remainder of the URL: (.*)
  12. #with the full URL: http://example.com/$1
  13. #make it a permanent redirect: R=301
  14. #stop rewriting and do the redirection immediately: L
  15. RewriteRule (.*) http://example.com/$1 [R=301,L]

URL: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.