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:


The following should NOT redirect there:


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 redirected.
I thought adding a slash after the 2nd parenthesis would do the job, but it just broke the redirecting.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?[^/] /?$ /index.php [L]
By : Wrikken

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

By : unbeli

This video can help you solving your question :)
By: admin