htaccess - How are htaccess files applied to subdirectories?
I have a rewrite rule:
RewriteRule ^Catalog/Custom_Pages/([^\.]+)\.html$ http://www.domain.com/New/Catalog/Custom_Pages/Custom_Pages_Main.php?cp=$1 [R]
The directory structure is domain.com/New/Catalog/
If I omit 'Catalog' at the front of the RewriteRule then the URL is not rewritten. The htaccess file is in the 'New' directory. So does the htaccess for 'New' only apply to its subdirectories or should it apply to all the subdirectories such that 'Catalog' could be开发者_运维百科 omitted? Is this probably a server setting?
If .htaccess file is in /New/
folder, then it will apply for this folder and all subfolders but all URL paths in RewriteRule
directives will be relative to /New/
folder.
If you want to omit Catalog/
part from RewriteRule pattern, then try this rule instead:
RewriteRule Custom_Pages/([^\.]+)\.html$ http://www.domain.com/New/Catalog/Custom_Pages/Custom_Pages_Main.php?cp=$1 [R]
Your current pattern clearly says "URL should start with Catalog" (check regex manual what ^
means).
The above rule can then be applied to Catalog/Custom_Pages/something.html
as well as to Pink-Kitten/Custom_Pages/something.html
.
The pattern will be matched to url of the page, from the directory, so for exemple :
http://www.domain.com/New/Catalog/Custom_Pages/test.html
From the directory /New the path to the page is :
Catalog/Custom_Pages/test.html
Then if the regexp pattern matchs Catalog/Custom_Pages/test.html
the rule will apply, otherway it will not be applied.
ps : if there is a .htaccess in Catalog
or Custom_Pages
their rules will be tested first.
精彩评论