- Aug. 31st, 2006
- 4 comments
This handy set of rules for mod_rewrite automatically redirects any URL ending in "/index.php" to the same URL ending in "/." It works for the root directory as well as subdirectories.
RewriteCond %{THE_REQUEST} ^GET\ /.*/index\.(php|html)\ HTTP
RewriteRule (.*)index\.(php|html)$ /$1 [R=301,L]
For example, "http://www.example.com/subdirectory/index.php" would be redirected to "http://www.example.com/subdirectory/."
This eliminates one of the peskier canonicalization issues with relative ease. It's a bit tricky because of the way mod_rewrite updates its variables during execution — hence the odd use of the variable {THE_REQUEST}. If anyone knows an easier way or finds a problem with it, leave a comment.
















