[英]redirecting http to https and www to non www on apache
我需要在我们的apache2和网站.htaccess上设置高级(对我来说)重定向(希望如此)。 我们希望任何将指向www.example.com和example.com或https://www.example.com的人都重定向到https://example.com
问题是域名之后的链接必须有效。 例如http://example.com/category/article/newest和https://www.example.com/category/article/newest将在重定向后指向正确的https://example.com/category/文章/最新
我们尝试了重定向,你可以在附加的.htaccess中看到,但问题是它是例如将http://www.example.com/category/article/newest重定向到https://example.com/
我们目前的.htaccess
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule .* public/index.php
SetEnv APPLICATION_ENV development
<IfModule mod_php.c>
php_flag magic_quotes_gpc off
php_flag register_globals off
</IfModule>
尝试将规则更改为:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.$ [NC]
RewriteRule .* https://example.com%{REQUEST_URI} [R=301,L]
这样,如果请求不是HTTPS 或请求以“www”开头,它将被重定向到HTTPS而没有“www”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.