重新写入和重写www。重定向和HTTPS重定向
我发现按照重写规则,我想结合使用。它们存储在/etc/apache2/sites-enabled/000-default.conf中,
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
不幸的是它没有一起工作,其中只有一个正在工作。
例如: 如果我打开 http://example.com/ 它将我重定向到 https://example.com/ 如果我打开 https://www.example.com/ 它将我重定向到 https://example.com/
到目前为止,一切都很好。
但是,如果我打开 http://www.example.com/ ...它无济于事。
为什么?
编辑:
<If "%{HTTP_HOST} == '^www\.example\.com$'">
RewriteRule ^(.*)$ https://example.com/$1 [NC,R=301,L]
</If>
<If "%{SERVER_PORT} != '^443$'">
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</If>
也不起作用。
i found following Rewrite Rules, i would like to combine. They are stored in the /etc/apache2/sites-enabled/000-default.conf
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
Unfortunately it is not working together, only one of them is working.
For example:
If i open http://example.com/ it redirects me to https://example.com/
If i open https://www.example.com/ it redirects me to https://example.com/
So far, so good.
But if i open http://www.example.com/ ... it does nothing.
Why?
Edit:
<If "%{HTTP_HOST} == '^www\.example\.com
Also is not working.
">
RewriteRule ^(.*)$ https://example.com/$1 [NC,R=301,L]
</If>
<If "%{SERVER_PORT} != '^443
Also is not working.
">
RewriteRule (.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</If>
Also is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论