本文介绍了htaccess的重定向非www到WWW preserving 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 preserving URI字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 15:20