Forum Moderators: phranque

Message Too Old, No Replies

redirects only for root directory

htaccess redirects only for files in root

         

igormaster

3:51 pm on Mar 31, 2008 (gmt 0)

10+ Year Member



I would like to create a rewrite rule _only_ for requests for _any_ files in the root directory.

So, for example, these would meet the condition(s):
www.mydomain.com/index.html
mydomain.com/page2.html
www.mydomain.com

But, these would not meet the condition(s):
www.mydomain.com/sub1/index.html
www.mydomain.com/sub1/sub1a/page2.html
mydomain.com/sub1/
www.mydomain.com/sub1 [If this last one, w/o the trailing slash, causes an additional coding problem, it is not essential]

A related question: Is there a rule that can distinguish between a request for the root directory (alone) and a request for any file in the root directory? In other words, between these two:

www.mydomain.com/page2.html [versus]
www.mydomain.com [with or w/o the trailing slash]

Thank you.

g1smd

7:52 pm on Mar 31, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you put the rules in the .htaccess file in the root, then be aware that THE_REQUEST does not contain the leading "/", so any URL with a "/" in it, must be a URL for a sub-folder.

For a few of your examples, the lack of trailing "/" in the URL is an additional problem. It is normal to fix those to add the trailing "/" to all such requests.