htaccess rewriterule for subfolder

时间:2012-02-01 13:17:51

标签: .htaccess https subdirectory

我有一个.htaccess文件,工作正常。 但是,不是/specialsubfolderhttp://www.mydomain.com/specialsubfolder/index.php重定向到401.shtml

所以,我修改了这样的.htacces:

RewriteEngine On
#part I of .htaccess, performed for everything

#stops part II from execution if specialsubfolder
RewriteCond %{REQUEST_URI} "/specialsubfolder/"
RewriteRule (.*) $1 [L]

#part II of .htaccess, performed for everything except specialsubfolder

工作正常。剩下的唯一问题是将specialsubfolder的所有http重定向到https。

不幸的是,下面的代码不起作用(无论如何都重定向到401.shtml错误页面)。为什么呢?

RewriteEngine On
#part I of .htaccess, performed for everything

#http to https for specialsubfolder
RewriteCond %{REQUEST_URI} "/specialsubfolder/"
RewriteCond %{HTTPS} !=on
RewriteRule ^(specialsubfolder/.*)$ https://www.mydomain.com/$1 [R=301,L]

#stops part II from execution if specialsubfolder
RewriteCond %{REQUEST_URI} "/specialsubfolder/"
RewriteRule (.*) $1 [L]

#part II of .htaccess, performed for everything except specialsubfolder

谢谢。

1 个答案:

答案 0 :(得分:3)

您收到错误是因为您的代码导致无限循环:

RewriteCond %{REQUEST_URI} "/specialsubfolder/"
RewriteRule (.*) $1 [L]

这里您只是捕获整个REQUEST_URI并将其转发到相同的REQUEST_URI。例如:/specialsubfolder/foo的URI将转发到/specialsubfolder/foo,然后一次又一次地转发相同的转发,直到Apache mod_rewrite超出默认递归限制并抛出错误。

这很容易解决,但我很难理解你的要求。你能用简单的语言向我简要介绍一下你使用重写规则实现的目标。