我正在使用.htaccess移动的重定向,我在下面的一个旧的职位发现这里。它的工作很好,但我需要从重定向规则排除几个目录。
我试过了:
RewriteRule !^your-directory($|/) http://www.example.com%{REQUEST_URI} [L,R=301]
这会删除目录。
还有:
RewriteCond %{REQUEST_URI} "/your-directory/"
这是没有用的。
我也试着把它们放在不同的地方。
我只需要这些目录不受重写规则的影响,甚至整个root .htaccess文件。
这是我用的
# Set an environment variable for http/https.
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=ps:http]
# Check if m=1 is set and set cookie 'm' equal to 1.
RewriteCond %{QUERY_STRING} (^|&)m=1(&|$)
RewriteRule ^ - [CO=m:1:example.com]
# Check if m=0 is set and set cookie 'm' equal to 0.
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [CO=m:0:example.com]
# Cookie can't be set and read in the same request so check.
RewriteCond %{QUERY_STRING} (^|&)m=0(&|$)
RewriteRule ^ - [S=1]
# Check if this looks like a mobile device.
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT}
"android|blackberry|ipad|iphone|ipod|iemobile|opera
mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
# Check if we're not already on the mobile site.
RewriteCond %{HTTP_HOST} !^m\.
# Check if cookie is not set to force desktop site.
RewriteCond %{HTTP_COOKIE} !^.*m=0.*$ [NC]
# Now redirect to the mobile site preserving http or https.
RewriteRule ^ %{ENV:ps}://m.example.com%{REQUEST_URI} [R,L]
# Check if this looks like a desktop device.
RewriteCond %{HTTP_USER_AGENT} "!
(android|blackberry|ipad|iphone|ipod|iemobile|opera
mobile|palmos|webos|googlebot-mobile)" [NC]
# Check if we're on the mobile site.
RewriteCond %{HTTP_HOST} ^m\.
# Check if cookie is not set to force mobile site.
RewriteCond %{HTTP_COOKIE} !^.*m=1.*$ [NC]
# Now redirect to the mobile site preserving http or https.
RewriteRule ^ %{ENV:ps}://example.com%{REQUEST_URI} [R,L]
1条答案
按热度按时间kxxlusnw1#
我想你的第二个RewriteCond就快到了。试着这样做:
将所需数量的目录放入directory 1中|目录2|等等。
如果REQUEST_URI不是以/directory 1或/directory 2开始,则应显示为“”。
它将匹配:
等等
我觉得这是你想要的。