htaccess重写除一个请求外的所有未找到的请求

时间:2019-01-31 01:48:34

标签: .htaccess mod-rewrite

除了一个自定义的请求外,我需要将所有未找到的请求(不是现有文件或目录)重定向到我的WP网站到另一个站点:

也就是说,如果我收到了:https://www.website1.com/foo转到https://www.website2.com/foo

但是如果我收到了https://www.website1.com/wplog,则该网址不会更改。

“ foo”和“ wplog”都不是真实的文件或目录。

RewriteEngine on    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/wplog
RewriteRule ^(.*)$ https://www.website2.com/$1 [L,NC,QSA]

但是我发现这些条件适用于我对找不到和找到的每个请求,

~# curl -I https://www.website1.com/wplog
    HTTP/1.1 302 Found
    Date: Thu, 31 Jan 2019 01:20:33 GMT
    Server: Apache
    Strict-Transport-Security: max-age=63072000; includeSubdomains;
    Location: https://www.website2.com//index.php
    Content-Type: text/html; charset=iso-8859-1


~# curl -I https://www.website1.com
    HTTP/1.1 302 Found
    Date: Thu, 31 Jan 2019 01:20:50 GMT
    Server: Apache
    Strict-Transport-Security: max-age=63072000; includeSubdomains;
    Location: https://www.website2.com//index.php
    Content-Type: text/html; charset=iso-8859-1

~# curl -I https://www.website1.com/foo
HTTP/1.1 302 Found
        Date: Thu, 31 Jan 2019 01:22:33 GMT
        Server: Apache
        Strict-Transport-Security: max-age=63072000; includeSubdomains;
        Location: https://www.website2.com//foo
        Content-Type: text/html; charset=iso-8859-1

0 个答案:

没有答案