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

移至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?

图片转代码服务由CSDN问答提供 功能建议

我正在使用Zend框架,我有漂亮的url控制器。 以下.htaccess正在工作,但它制作搜索引擎优化,看到我们作为一个页面的四个链接。

  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正确执行此操作? 以便使用 https:// www 安全登陆以上输入网址。 在前面总是?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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.

    点赞 打赏 评论

相关推荐 更多相似问题