.htaccess重定向多次重写

时间:2012-08-24 18:01:52

标签: apache .htaccess

我正在尝试将一些选择页面重定向到HTTPS。我找到了很多例子,但它们似乎与我目前的htaccess文件中没有什么关系。我目前的htaccess已经

RewriteEngine On
Options +FollowSymLinks
# Redirect all other domains to the primary
RewriteCond %{HTTP_HOST} ^(www\.?|)(domain1\.com|domain2\.com|domain3\.com|\.co)$
RewriteRule ^(.*)$ http://www.prefferreddomain.com/$1 [R=301,L]
# Error Documents
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
#Cache Settings, etc. after this

我目前在我的htaccess文件中进行搜索引擎优化,因为我们拥有多个域名(20+)。无论如何,我想要3个页面重定向到HTTPS,但我尝试过的所有示例都没有按预期工作。我不确定是否应该在当前位于htaccess文件中的重定向之前或之后放置它们。

应该重定向到https的页面是logon.php& chat.php。所以我试过

RewriteEngine On
Options +FollowSymLinks

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (logon.php)
RewriteRule (.*) https://www.preferreddomain.com%{REQUEST_URI} 

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (chats.php)
RewriteRule (.*) https://www.preferreddomain.com%{REQUEST_URI}

# Redirect all other domains to the primary
RewriteCond %{HTTP_HOST} ^(www\.?|)(domain1\.com|domain2\.com|domain3\.com|\.co)$
RewriteRule ^(.*)$ http://www.prefferreddomain.com/$1 [R=301,L]
# Error Documents
ErrorDocument 401 /errors/401.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
#Cache Settings, etc. after this

但是这没用。有没有人有任何指示。

2 个答案:

答案 0 :(得分:0)

[R=301,L]添加到每个https://规则的末尾。如果没有L,规则会将URI标记为重定向,但URI会继续通过重写引擎的其余部分,并且也会与最后一条规则匹配。

答案 1 :(得分:0)

原因是它不起作用的原因是因为我们的主机网络解决方案正在使用SSL代理,因此任何检测协议的服务器端都无法正常工作并且通常会导致循环。

相关问题