English 中文(简体)
清除WWWWW
原标题:ModRewrite weird redirect behavior on removing WWW

我试图从<代码>URL开始就我的项目使用某些规则,但我提出一些问题。

我的服务器结构是:

domain.com/beta_folder
domain.com/beta_folder/page+type
domain.com/beta_folder/page+type/content+name
domain.com/beta_folder/page+type/content+name/edit
domain.com/beta_folder/page+type/content+name/etc.

domain.com/beta_folder/.htaccess //here is where my htaccess is

该网站完全符合本规定

RewriteEngine On
RewriteRule ^(page+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2

我的用意是删除<条码>www,因此,我已添加了这一规则,但那是没有有效的。

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com$1 [R=301,L]
RewriteRule ^(page+type/)([a-zA-Z0-9_+-]+)[/]?$ page_folder/page.php?varname=$2

我的问题始于我域名前面的“数字<代码>www:

著作

http://domain.com/beta_folder/page+type/content+name

i)

http://www.domain.com/beta_folder/page+type/content+name

改写规则后,我改用

http://www.domain.compage+type/content+name

如果删除<条码>www规则,则问题依然有效。

不幸的是,我无法公开测试我的领域。

基本上,如果我写的话

 http://www.domain.com/beta_folder

规则发给我

 http://domain.com/

我找到解决这一问题的唯一途径是写我的网站的夹,以便:

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

I don t undestand why I should write the folder, because my rewrite cond affects http://www.domain.com/folder_name/contents and not http://www.domain.com/contents

为什么从重写中遗漏了“姓名/代码”的编号。

问题回答

引证这一点是你统治的明显不同例子:

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

如果这不解决你的问题,那么大声疾呼。





相关问题
URL rewrite in IIS6 - Third party tools

I have collected the following api/sdk/whatever which provide modules for doing url rewriting in IIS 5/6/7. Some are free-open source and some require $. I haven t tried any of them. I would like to ...

Rewrite spring-security redirect URLs

I m trying to get Tuckey UrlRewriteFilter to tidy up URLs for my webapp. One problem I ve got is that when spring-security notices that an anonymous user is trying to access a protected resource it ...

ASP.NET Friendly URLs

In my research, I found 2 ways to do them. Both required modifications to the Application_BeginRequest procedure in the Global.Asax, where you would run your code to do the actual URL mapping (mine ...

Could I get by HttpModule the URL that contains * before?

My web-site is working under ASP.NET 3.5, IIS7, Integrated pipiline mode. My HttpModule is getting request to all resources, including URLs like this: http://my-site.com/address And I would support *...

Domains & Foreward Slash

This is rather difficult to explain so please bear with me. We will be hosting 4 websites on our server and the plan is to have each site sit under its own domain: site-a.com site-b.com sub1.site-b....

URL Mod-Rewrite

I currently have a working URL: http://example.com/security-services.php?service=fixed-camera-surveillance and then I have PHP say, $_REQUEST[ service ] to do some stuff... But I d like to ...

热门标签