加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – .htaccess将非WWW重定向到WWW保留URI字符串

发布时间:2020-12-13 16:39:34 所属栏目:PHP教程 来源:网络整理
导读:我正在运行CodeIgniter平台,它使用.htaccess来接受URL http://www.mysite.com/controller/function/argument 我目前使用一些.htaccess重写,即(简化): RewriteEngine OnRewriteCond %{REQUEST_URI} !^(/index.php|/images|/assets)RewriteRule ^(.*)$/index
我正在运行CodeIgniter平台,它使用.htaccess来接受URL
http://www.mysite.com/controller/function/argument

我目前使用一些.htaccess重写,即(简化):

RewriteEngine On
RewriteCond %{REQUEST_URI} !^(/index.php|/images|/assets)
RewriteRule ^(.*)$/index.php/$1 [L]

我想添加重写规则,将所有非www请求重定向到www.我也希望域名后面的URI字符串在重定向中保持一致.例如,如果用户请求http://mysite.com/controller/function/argument,我希望.htaccess文件在浏览器中重写请求,网址为http://www.mysite.com/controller/函数/参数,然后处理请求.

应该是这样的:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读