开发者

Mod_Rewrite Subdomain/Path Rewriting Issue

I have an existing rule in place to rewrite:

subdomain.domain.com

to this format:

domain.com/directory/index.aspx?id=subdomain

RewriteCond %{HTTP_HOST} !^www\. [NC]<br/>
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]<br/>
RewriteRule ^$ /directory/index.aspx?id=%1 [NC,QSA,L]

I need to update this to support:

subdomain.domain.com/foo

to this format:

domain.com/directory/foo.aspx?id=subdomain

I've tried to make the following changes to my existing rule without success:

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com/(.*)
RewriteRule ^$ /directory/%2.aspx?id=%1 [NC,QSA,L]

It doesn't appear that the second Rewrite开发者_如何学编程Cond is being matched. Am I missing something easy? Should this be handled differently?

Thanks.


The HTTP_HOST variable contains the value in the HTTP "Host:" header -- that is, in your case, "subdomain.domain.com". The trailing URI (slash, etc.) is not there.

You need to match that part of the URL in your rule:

RewriteCond %{HTTP_HOST} !^www\. [NC]<br/>
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]<br/>
RewriteRule ^/([^/]+)$ /directory/$1.aspx?id=%1 [NC,QSA,L]

Salut,

Jordi.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜