Problem detecting empty REQUEST_URI with Apache mod_rewrite

后端 未结 8 1833
南方客
南方客 2021-01-03 00:57

I am running Apache witha redirect rule like this:

RewriteCond %{HTTP_HOST} ^1st-domain\\.com
RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]


        
相关标签:
8条回答
  • 2021-01-03 01:25

    This should work:

    RewriteCond %{HTTP_HOST} ^1st-domain\.com
    RewriteRule ^$ http://3rd-domain.com [R=permanent,L]
    
    RewriteCond %{HTTP_HOST} ^1st-domain\.com
    RewriteRule ^(.+)$ http://2nd-domain.com/$1 [R=permanent,L]
    

    Hope it helps!

    Note: REQUEST_URI is slightly different between httpd.conf and .htaccess, it starts with an extra backslash in httpd.conf. This means that in httpd.conf the first rewrite rule should be ^\/$, not just ^$.

    0 讨论(0)
  • 2021-01-03 01:25

    On multisites such redirection works for me for empty requests :

    RewriteCond %{HTTP_HOST} ^1st-domain\.com$
    RewriteCond %{REQUEST_URI} "^/$"
    RewriteRule ^$ http://3rd-domain.com/ [R=permanent,L]
    
    0 讨论(0)
提交回复
热议问题