本文介绍了.htaccess 将非 WWW 重定向到 WWW 保留 URI 字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在运行 CodeIgniter 平台,它使用 .htaccess 来接受像

I'm running the CodeIgniter platform, which uses .htaccess to accept URLs like

http://www.mysite.com/controller/function/argument

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

I currently use some .htaccess rewrites, namely (simplified):

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/function/argument 然后处理请求.

I want to add a rewrite rule that redirects all non www requests to www. I also want the URI string following the domain name to stay the same in the redirect. For instance, if a user makes a request for http://mysite.com/controller/function/argument, I want the .htaccess file to rewrite the request in the browser as http://www.mysite.com/controller/function/argument and then process the request.

推荐答案

应该是这样的:

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

这篇关于.htaccess 将非 WWW 重定向到 WWW 保留 URI 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:57