开发者

Mod_rewrite matching both subdomain and query string

开发者 https://www.devze.com 2023-02-05 08:30 出处:网络
I\'m currently mod_rewriting domain.com/a/123/abc to page.php?this=123&that=abc with: RewriteRule ^a/([^/]+)/([^/]+)/?$ page.php?this开发者_JS百科=$1&that=$2 [L]

I'm currently mod_rewriting domain.com/a/123/abc to page.php?this=123&that=abc with:

RewriteRule ^a/([^/]+)/([^/]+)/?$ page.php?this开发者_JS百科=$1&that=$2 [L]

Additionally I now want to mod_rewrite a.domain.com/123/abc to page.php?this=123&that=abc

So both a.domain.com/123/abc and domain.com/a/123/abc will redirect to page.php?this=123&that=abc

My problem is matching both the subdomain and the query string. This is what I've been working on but it's still not rewriting properly.

RewriteCond %{HTTP_HOST} ^a\.domain\.com/ [NC]
RewriteCond %{QUERY_STRING} /([^/]+)/([^/]+)/?$ [NC]
RewriteRule ^(.*) /a/$1/$2 [L]

Note that wildcard domains are set up (*.domain.com). It is just the htaccess mod_rewriting that is failing.


Is it the trailing / on your RewriteCond?

RewriteCond %{HTTP_HOST} ^a\.domain\.com/

Should be

RewriteCond %{HTTP_HOST} ^a\.domain\.com
0

精彩评论

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