当它是www或http://或不带www和http://时,移动到https://www?

时间 2019-01-07
阅读 48
点赞 0
收藏 0
连接yumyumyum

我使用的是Zend框架,其中我有漂亮的URL控制器。htaccess正在工作,但它使seo将我们视为一个页面的四个链接。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

我需要使用htaccess执行以下修复:

www.stackoverflow.com/nice-looking-url=https://www.stackoverflow.com/nice-looking-url

stackoverflow.com/nice-looking-url=https://www.stackoverflow.com/nice-looking-url

http://www.stackoverflow.com/nice-looking-url=https://www.stackoverflow.com/nice-looking-url

http://stackoverflow.com/nice-looking-url=https://www.stackoverflow.com/nice-looking-url

如何正确使用htaccess?这样,上面的输入URL就可以安全地通过https://www. 总是在前面?

建议答案

完全访问.htaccess,如下所示:

RewriteEngine On

## add www and turn on https in same rule - main domain
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

## turn on https in same rule - sub domain
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

请确保使用新浏览器测试更改,以避免使用旧的浏览器缓存。

👍 0