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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!