如果uri中不存在某些字符串,则重写规则

时间:2016-12-28 18:24:40

标签: apache redirect mod-rewrite virtualhost

我正在尝试重定向所有请求,如果URI中不存在某些字符串。

如果我写这个 - 重定向所有请求,字符串“/ clkf”存在,那么一切正常:

RewriteCond %{HTTP_HOST} ^clk\.example\.de$ [NC]
RewriteCond %{REQUEST_URI} ^/clkf$ [NC]
RewriteRule ^/(.*)$ https://www.example.de/ [L,R]

但是当我想制作oposite时 - 重定向除了这个有字符串“/ clkf”之外的所有其他请求,那么它会重定向所有内容。

RewriteCond %{HTTP_HOST} ^clk\.example\.de$ [NC]
RewriteCond %{REQUEST_URI} !^/clkf$ [NC]
RewriteRule ^/(.*)$ https://www.example.de/ [L,R]

最终结果应为:

http://clk.example.de -> https://www.example.de
http://clk.example.de/bla -> https://www.example.de
http://clk.example.de/clkf?adasd -> NOT REDIRECT

BTW:规则是用Apache Vhost编写的,而不是写在.htaccess文件中

由于 NIK

0 个答案:

没有答案
相关问题