我的客户拥有MAINSITE.com的SSL证书,但通过OTHERSITE.com获得了大量流量。
客户希望所有访问者始终使用HTTPS。
因此,我的规则首先检查OTHERSITE.com,如果找到则重定向到https://MAINSITE.com。
然后我检查是否使用HTTPS并重定向,如果没有。
然后有一系列规则旨在使用URL中的子目录来提取内容和加载模板。
我的问题是这些规则是否与应有的一样有效,是否有人发现它们的编写方式存在问题?我不是mod_rewrite专家。
此外,我们有一些用户在网站的WWW版本加载时报告IE拯救他们,但我不明白为什么?有什么建议吗?
ErrorDocument 404 /index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} OTHERSITE.com [NC]
RewriteRule ^(.*)$ https://MAINSITE.com/$1 [L,R=301]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^products - [L,NC]
RewriteRule ^sauces$ /sauces.php?sauce=our-hot-sauce [L,QSA]
RewriteRule ^sauces/([^/\.]+)/?$ /sauces.php?sauce=$1 [L,QSA]
RewriteRule ^recipes/([^/\.]+)/?$ /recipes.php?cat=$1 [L,QSA]
# user has cleared recipe name but not cat AND left trailing slash
RewriteRule ^recipe/([^/\.]+)/$ /recipes.php?cat=$1 [L,QSA]
# has sauce/cat and recipe name
RewriteRule ^recipe/([^/\.]+)/([^/\.]+)/?$ /recipe.php?cat=$1&rec=$2 [L,QSA]
# user has cleared recipe name but not cat
RewriteRule ^recipe/([^/\.]+)$ /recipes.php?cat=$1 [L,QSA]
RewriteRule ^([^/\.]+)/?$ /page.php?page=$1 [L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /page.php?page=$1&sub=$2 [L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /page.php?page=$1&sub=$2&subsub=$3 [L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /page.php?page=$1&sub=$2&subsub=$3&subsubsub=$4 [L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /page.php?page=$1&sub=$2&subsub=$3&subsubsub=$4&subsubsubsub=$5 [L,QSA]
答案 0 :(得分:1)
其他规则如精细但前2 301
规则可以组合成一个:
RewriteCond %{HTTP_HOST} ^(www\.)?OTHERSITE\.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://MAINSITE.com%{REQUEST_URI} [L,R=301,NE]