The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other How to remove subdirectories using mod_rewrite in .htaccess Reply To: How to remove subdirectories using mod_rewrite in .htaccess


But if I were to do what you suggest, I would need to create every rewrite rule for each file.


The example I gave above matches the URL against alphabetic characters followed by a slash, and rewrites it to the /cat/play directory with a .html extension. That’s what gathered you wanted, from your description:

when people go to they’re able to access without redirecting, which means, in the address bar it still shows

This example meets that description, to the letter. Did you try it out?

If you want to rewrite to different directories (e.g., play or rest, as in your third code example), but without any way to distinguish which directory from the URL, then yes: you will have to make a new rule for every file. mod_rewrite cannot “guess” what you want it to do.

You might consider adding an extra part to the url, for example:

RewriteRule ^play/([A-Za-z]+)/$ /cat/play/$1.html [L]
RewriteRule ^rest/([A-Za-z]+)/$ /cat/rest/$1.html [L]

If there is something else I am not understanding about your question, please describe it further.