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

#176721
ewisely
Participant

Sorry for not being clear.

My site url (under /q/) used to be like that:

mysite.com/q/sleep-rest.htm
mysite.com/q/play-study.htm
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) mysite.com/sleep-rest/ or mysite.com/sleep-rest, both will retrieve content from mysite.com/q/sleep-rest.htm

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 mysite.com/q/sleep-rest.htm to mysite.com/sleep-rest/and 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.