是https或www时(是www还是http://或没有www和http://时)? [英] Move to https://www, when it is www or http:// or without www and http://?

查看:125
本文介绍了是https或www时(是www还是http://或没有www和http://时)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Zend框架,其中有漂亮的URL控制器.紧随.htaccess之后,它仍然有效,但它使SEO看到我们是一页的四个链接.

I am using Zend framework where i have nice looking url controllers. Following .htaccess is working but its making SEO to see us as four links for one page.

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进行以下修复:

I need to do following fix using htaccess:

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

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

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正确执行操作?因此上述输入网址可以通过 https://www 安全着陆.总是在前面?

How to do it correctly using htaccess? so that above input urls are safely landing with https://www. in front always?

推荐答案

具有完整的.htaccess文件,如下所示:

Have your full .htaccess like this:

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]

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

Make sure to use a new browser to test your changes to avoid old browser cache.

这篇关于是https或www时(是www还是http://或没有www和http://时)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆