mod_rewrite: redirect top level directories to a file
I'd like to redirect all top level directories to a file using mod_rewrite.
So the following should redirect there:
- http://example.com/test
- http://example.com/test8/
- http://example.com/test_9231/
The following should NOT redirect there:
- http://example.com/test.php
- http://example.com/test_9231/test/
- http://example.com/test/test.php
- http://example.com/test_9231/test
None of the directories will physically exist. Directory names will only contain these characters: A-Za-z0-9_-
I tried this RewriteRule /(.*) /index.php [L]
but subdirectories are still red开发者_Python百科irected.
RewriteRule ^/[A-Za-z0-9_-]+/?$ /index.php
This will match a slash, then a name according to your spec, then another optional slash, then end of string, so subdirectories won't match
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?[^/]+/?$ /index.php [L]
精彩评论