Skip to content

Instantly share code, notes, and snippets.

@josephspurrier
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephspurrier/9847516 to your computer and use it in GitHub Desktop.
Save josephspurrier/9847516 to your computer and use it in GitHub Desktop.
Apache sub folder configuration for Trailing Slash Solution - http://josephspurrier.com/trailing-slash-solution/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
# Strip main index.php and query string
RewriteCond %{THE_REQUEST} ^GET./+test/+index\.php\?
RewriteRule . /test/? [R=301,NE,L]
# Strip multiple slashes and query string
RewriteCond %{THE_REQUEST} (.*)//(.*)
RewriteRule (.*) /test/$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>
@josephspurrier
Copy link
Author

If you place a dynamic application using the Front Controller pattern (index.php) in a sub folder, place this file in the same sub folder and then change the 5 instances of 'test' to your folder name. This also requires you to use the Apache root folder configuration here: https://gist.github.com/josephspurrier/9835946.

By using these two scripts, both applications will handle pages the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment