开发者

Exclude certain subfolders and domains in redirects

开发者 https://www.devze.com 2022-12-11 23:15 出处:网络
This is a continuation from Redirect only HTML files? How can I change my .htaccess to make it exclude certain subfolders or subdomains from the HTML-only redirect? I tried doing using this code to e

This is a continuation from Redirect only HTML files?

How can I change my .htaccess to make it exclude certain subfolders or subdomains from the HTML-only redirect? I tried doing using this code to e开发者_JAVA百科xclude the 'downloads' subfolder and the 'dev' and 'support' subdomains, but it didn't work:

RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} !download [OR]
RewriteCond %{HTTP_HOST} !faq
RewriteCond %{HTTP_HOST} !support [OR]
RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]


You need to check REQUEST_URI or the whole match of the RewriteRule $0 for this; HTTP_HOST does only contain the host name of the current request. You also need to change the logical expression of your condition:

RewriteCond %{HTTP_HOST} ^pandamonia\.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia\.us$
RewriteCond %{REQUEST_URI} !^/download/
RewriteCond %{REQUEST_URI} !^/faq/
RewriteCond %{REQUEST_URI} !^/support/
RewriteRule /.+\.html$ http://pandamonia.us/ [L]


For those looking for a quick bit of insight into Gumbo's previous reply (where he mentions the situations for when to (and not to) use [OR], I found this WMW thread very helpful: http://www.webmasterworld.com/apache/3522649.htm

0

精彩评论

暂无评论...
验证码 换一张
取 消