dongshungai4857 2019-01-06 22:18
浏览 148
已采纳

移至https:// www,当它是www或http://或没有www和http://?

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]

I need to do following fix using 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

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

  • 写回答

1条回答 默认 最新

  • duankang8114 2019-01-08 06:44
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效