htaccess的非www。到www重定向,并要求重写的index.php [英] htaccess non-www. to www redirect AND request rewrite to index.php

查看:273
本文介绍了htaccess的非www。到www重定向,并要求重写的index.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图合并两个htaccess的规则集在同一时间:

Trying to combine two htaccess RewriteRules at the same time:

1)把所有非www网址到www
2)将所有请求的index.php

1) transform all non-www URLs to www
2) send all requests to index.php

数2作品与在生产中以下设置:

Number 2 works with the following settings in production:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA]

但与合并

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

的URL表现为应该使用万维网网址时,但有趣地与非www网址使用时

the URLs behave as supposed to when using a www url, but funnily when used with a non-www url.

例如。 http://mydomain.com/customername/admin/signin 成为
http://www.mydomain.com/index.php/admin/signin?/customername/admin/signin

E.g. http://mydomain.com/customername/admin/signin becomes
http://www.mydomain.com/index.php/admin/signin?/customername/admin/signin

虽然URL应该仅仅停留在相同的无刷新和参数/客户名称/管理/登入资讯应传递到index.php ...

although the URL should just stay the same without a refresh and the parameters "/customername/admin/signin" should be passed to index.php...

这是我如何能做到这一点有什么建议?我想以后mydomain.com的网址保持不变(因为我的解决方案目前还),但增加了www。盈方的URL。

Any tips on how I can achieve this? I want the URL after mydomain.com to stay the same (as my solution currently does) but add the www. infront of the URL.

推荐答案

它看起来像你只需要添加HTTP_HOST检查的的杂物箱重写的index.php。

It looks like you just need to add the HTTP_HOST checking before the catch-all rewrite to index.php.

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

这重定向到www的的任何一个URI已被改写成包罗万象的,则:

This redirects to www before any of the URI have been rewritten to the catch-all, then:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA]

执行包罗万象的,这恰好经过非www得到301重定向到www的域名。

Do the catch-all, which happens after the non-www gets 301 redirected to the www domain.

这篇关于htaccess的非www。到www重定向,并要求重写的index.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆