在编写包含以下规则的复合重写时遇到困难:
要求:
例如
http://example.com/checkout/123 – > https://wwws.example.com/checkout/123或http://example.com/checkout – > https://wwws.example.com/checkout/ 123
我目前做了什么:
我目前有一系列的重写,将www重写为非www:
RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
这是有问题的,因为当http: http : //wwws.example.com的http请求redirect到http://www.wwws.example.com 。
我将如何实现重写将满足我的要求?
不要使用HTTP_HOST:
RewriteCond %{HTTP_HOST} ^!example.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
我的偏好是这样的:
RewriteCond %{HTTP_HOST} !^www.*$ [NC] RewriteRule ^/.+www\/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
或者更简单:
<VirtualHost *:80> ServerAlias example.com RedirectMatch permanent ^/(.*) http://www.example.com/$1 </VirtualHost>
阅读方式:find更多的其他方法。
要将httpsredirect到http:
RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^/(.*) http://%{SERVER_NAME}/$1 [L,R]
要么:
RewriteCond %{HTTP} off RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}