【发布时间】:2017-01-29 23:41:53
【问题描述】:
我有一个奇怪的问题。我的重写规则似乎正如我所期望的那样工作,但不适用于子页面。
www 到无 www 总是有效,但在某些页面上强制 https 无效。
所有规则都在主页上起作用,所以这一切都很好。
<IfModule mod_rewrite.c>
# Wordpress related rewrite.
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# www and https rules.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
</IfModule>
结果:
- http://example.com -> https://example.com(好)
- http://www.example.com -> https://example.com(好)
- https://example.com -> https://example.com(好)
- https://www.example.com -> https://example.com(好)
但是,子页面似乎无法正常工作:
- https://example.com/page -> https://example.com/page(好)
- https://www.example.com/page -> https://example.com/page(好)
- http://example.com/page -> http://example.com/page(坏)
- http://www.example.com/page -> http://example.com/page(坏)
知道如何改进此重写以在没有 www 和 https 的情况下工作,无论我身在何处?
谢谢
【问题讨论】:
标签: .htaccess mod-rewrite https url-rewriting