Last active
August 29, 2015 13:57
-
-
Save josephspurrier/9835946 to your computer and use it in GitHub Desktop.
Apache root configuration for Trailing Slash Solution - http://josephspurrier.com/trailing-slash-solution/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Remove Apache variations on URL, best for SEO | |
Options -MultiViews | |
<IfModule mod_dir.c> | |
# Ensure index.php is only allowed as index | |
DirectoryIndex index.php | |
</IfModule> | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
# Strip main index.php and query string | |
RewriteCond %{THE_REQUEST} ^GET./+index\.php\? [NC] | |
RewriteRule . /? [R=301,NE,L] | |
# Strip multiple slashes and query string | |
RewriteCond %{THE_REQUEST} (.*)//(.*) | |
RewriteRule (.*) /$1? [R=301,NE,L] | |
# If real file has a trailing slash, remove it and strip the query string | |
RewriteCond %{REQUEST_FILENAME} -f | |
RewriteRule ^/?(.*[^index.php])/$ /$1? [R=301,NE,NC,L] | |
# Check for file | |
RewriteCond %{REQUEST_FILENAME} !-f | |
# Send all other requests to index.php | |
RewriteRule . index.php [L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A sub folder Apache config file is available here: https://gist.github.com/josephspurrier/9847516.
By using these two scripts, both applications will handle pages the same.