【发布时间】:2015-11-08 09:36:49
【问题描述】:
我就是想不通。我的 .htaccess 规则如下所示:
RewriteEngine On
RewriteBase /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,QSA,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,QSA,L]
RewriteRule ^(en|de)(/.*)?$ $2?lang=$1 [L,NC]
我的计划显然是重定向如下:
- http://example.com/whatever/goes/here => https://example.com/whatever/goes/here
- http://example.com/ => https://example.com/
- http://www.example.com/example => https://example.com/example
- https://www.example.com/ => https://example.com/
- 并将所有 /en 或 /de 请求 uri 附加为查询字符串 ?lang=de|en
所以最后一条规则按预期工作。奇怪的行为是对http://www.example.com/test 或http://example.com/test 的请求被重定向到https://example.comtest。看起来规则 RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 在 %{SERVER_NAME} 和请求 uri $1 之间的斜线只是没有添加。
如果有人能指出正确的方向,我会很高兴。
【问题讨论】:
标签: .htaccess mod-rewrite redirect