how to make mod_rewrite to redirect from subdomains to querystring?

后端 未结 1 559
萌比男神i
萌比男神i 2021-01-22 20:02

I want to make mod rewrite as the following example :

from google.com.mydomain.com to mydomain.com/index.php?domain=google.com

I use like

Rewrit         


        
1条回答
  •  -上瘾入骨i
    2021-01-22 20:18

    It is due to the incorrect regex. Try this rule:

    RewriteCond %{HTTP_HOST} !^www [NC]
    RewriteCond %{QUERY_STRING} !domain=
    RewriteCond %{HTTP_HOST} ^(.+?)\.mydomain\.com$ [NC]
    RewriteRule ^(.*)$ /index.php?domain=%1 [L,QSA]
    

    In your rule you're using [^\.]+ which matched until a dot is found therefore it is matching google instead of google.com.

    0 讨论(0)
提交回复
热议问题