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