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


Sorry for not being clear.

My site url (under /q/) used to be like that:
and so on…

I’ve used RewriteRule ^/([a-zA-Z0-9_-]+)/?$ /q/$1.htm so that when people click on (or type into the browser) or, both will retrieve content from

However, because this site is pretty old and has quite a number of old urls pointing back from other websites. So, I want to do a permanent redirect of to likewise for the rest of the urls to avoid creating confusion to my visitors.

Since my files are all under /q/ folder, I’m trying to use a single line of code (RewriteRule ^q/([a-zA-Z0-9_-]+)\.htm$ /$1/ [R=301,L]) to perform the 301 redirect for all old urls but it invokes a redirect loop.

Is it actually possible to work out something like that? Appreciate your help.