Posted By

wizard04 on 07/24/09


Tagged

regex redirect htaccess apache rewrite


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
NARKOZ


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


 / Published in: Apache
 

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

  1. #****************************************
  2. # Apache redirect from *.example.com to example.com
  3. #****************************************
  4.  
  5. RewriteEngine on
  6.  
  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$
  10.  
  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]

Report this snippet  

You need to login to post a comment.