脚本宝典收集整理的这篇文章主要介绍了php – codeigniter将非www重定向到www,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我去mysITe.COM/site/something我会被重定向到mysite.com/something
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ rewriterule (.*) http://www.mysite.com/$1 [R=301,L]
还尝试过:
RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www.mysite.com [NC] RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
编辑:
这是我使用的代码,基于Alfonso Rubalcava的回答:
if (substr($_SERVER['SERVER_NamE'],3) != 'www') { if ($_SERVER['REQUEST_URI'] == '//site/') { header('HTTP/1.1 301 Moved PErmanently'); header('Location: http://www.site.com/site/'); exit; } header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.site.com' . $_SERVER['REQUEST_URI']); exit; }
if(substr($_SERVER['SERVER_NAME'],3)=="www"){ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://yourdomain.tdl/".$_SERVER['REQUEST_URI']); }else{ //the current contents of your file }
编辑
我读错了你的问题,答案是:
if(substr($_SERVER['SERVER_NAME'],3)!="www"){ header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.yourdomain.tdl/".$_SERVER['REQUEST_URI']); }else{ //the current contents of your file }
以上是脚本宝典为你收集整理的php – codeigniter将非www重定向到www全部内容,希望文章能够帮你解决php – codeigniter将非www重定向到www所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。