Forums

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

#170837
__
Participant

Yup, I tried your example and that works for a single file.

Maybe I am misunderstanding what you are saying. Take these URLs, for example:

example.com/fun/
example.com/exercise/
example.com/competition/
example.com/games/

You do not need to create new rules for each of these URLs. The single rule:

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

Will handle all of them.

Now, if you throw in some other URLs:

example.com/sleep/
example.com/bedtime/

…mod_rewrite won’t know that they are meant to go to the “rest” directory. It will send them to the “play” directory because that’s the only one it knows about.

If there is only one parameter in the URL, then that’s the only one mod_rewrite can make decisions based on.

If you add a “category” parameter, then it could make that decision:

example.com/play/fun/
example.com/play/exercise/
example.com/play/competition/
example.com/play/games/
example.com/rest/sleep/
example.com/rest/bedtime/

with

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

Are we talking about the same thing, or am I mixed up about your question?