htaccess Rewrite Rule for subdomain to page

前端 未结 2 1935
死守一世寂寞
死守一世寂寞 2020-12-19 19:04

Currently I have a page residing at:

http://www.example.com/site/page

In my htaccess I have the current rule:

RewriteRule ^         


        
相关标签:
2条回答
  • 2020-12-19 19:11

    Try this one :

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC]
    RewriteRule .* retailer.php?linklabel=%1 [L,QSA]
    
    0 讨论(0)
  • 2020-12-19 19:20

    Try:

    RewriteCond %{HTTP_HOST} !^www.[NC]
    RewriteCond %{HTTP_HOST} ^(.+?)\.example.com$ [NC]
    RewriteRule ^$ retailer.php?linklabel=%1 [L,QSA]
    

    You can't match against the host in a RewriteRule, so you'll need to do it against the %{HTTP_HOST} var in a RewriteCond, then use the %1 backreference to get that match.

    This will currently only match against URI's that are exactly /. So it won't match against http://page.example.com/something unless you change the regular express at from ^$ to ^something$.

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