Problem detecting empty REQUEST_URI with Apache mod_rewrite

后端 未结 8 1832
南方客
南方客 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:02

    I tried the options stated on this page, all I wanted was to check if the REQUEST_URI is empty (or in this particular case, a /):

    # Check of the request uri is just 1 char long (checking for a slash was harder):
    RewriteCond %{REQUEST_URI} ^.$
    
    0 讨论(0)
  • 2021-01-03 01:07

    Your rules redirects request with empty QUERY_STRING.

    For empty request_uri, you can use

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

    The first rule will first match <empty>, then tests for <non-empty or empty> (which can't be <empty> now since we've processed it before)

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

    If request is empty apache 'redirects' to index.html so -RewriteCond %{REQUEST_URI} index- might help you.

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

    I am using the following to catch empty REQUEST_URL:

    RewriteEngine on

    RewriteCond %{REQUEST_URI} "^/$"

    RewriteRule ^(.*) http://%{HTTP_HOST}/my/another/url

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

    This should work:

    RewriteCond %{HTTP_HOST} ^1st-domain\.com
    RewriteRule ^(.*)$ http://2nd-domain.com$1 [R=permanent,L]
    RedirectMatch ^/$ http://3rd-domain.com 
    
    0 讨论(0)
  • 2021-01-03 01:19

    This worked for me:

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

    whitout the quotes on the empty validation

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