Skip to content

Instantly share code, notes, and snippets.

@stith
Created May 6, 2011 03:41
Show Gist options
  • Save stith/958409 to your computer and use it in GitHub Desktop.
Save stith/958409 to your computer and use it in GitHub Desktop.
The ultimate Magento SEO .htaccess rewrite rule set
# Grab the protocol being used
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]
# Force WWW
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ %{ENV:ps}://www.%{HTTP_HOST}/$1 [R=301,L]
# Remove index.php from URLs
RewriteCond %{REQUEST_URI} ^/index.php/?
RewriteRule ^index.php/?(.*)$ %{ENV:ps}://%{HTTP_HOST}/$1 [R=301,L]
# Force trailing slashes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !.html
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{ENV:ps}://%{HTTP_HOST}/$1/ [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment