redirect root to sub directory


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



Copy this code and paste it in your HTML
  1. RewriteEngine on
  2. RewriteBase /
  3.  
  4. # Rewrite Rule 1: Redirect all direct requests for URLs including the foldername to non-folder URLs at www.
  5. # Note we can't use REQUEST_URI because you get recursion. You only want to redirect the original string.
  6. RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /blog/.*\ HTTP/
  7. RewriteRule ^blog/(.*)$ http://domain.com/$1 [R=301,L]
  8.  
  9. # Rewrite Rule 2: Redirect all www to non-www and preserve folder and file path.
  10. RewriteCond %{HTTP_HOST} ^www.^domain\.com [NC]
  11. RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
  12.  
  13. # Rewrite Rule 3: Rewrite non-folder URLs to folder filepath.
  14. RewriteCond %{REQUEST_URI} !^/blog/
  15. RewriteRule ^(.*)$ /blog/$1 [L]

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.