无法从.htaccess移动重定向中排除目录吗?

时间:2019-06-18 00:40:52

标签: php .htaccess

我正在使用.htaccess移动重定向,在下面的旧帖子中可以找到。效果很好,但是我需要从重定向规则中排除几个目录。

我尝试过:

RewriteRule !^your-directory($|/) http://www.example.com%{REQUEST_URI} [L,R=301]

哪个杀死目录。

并且:

RewriteCond %{REQUEST_URI} "/your-directory/"

什么都不做。

我也尝试将它们放置在不同的地方。

什么代码以及在哪里放置它。我只需要这些目录不受重写规则甚至整个根.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 个答案:

答案 0 :(得分:0)

您认为您的第二个RewriteCond快要出现了。尝试这样的事情:

RewriteCond %{REQUEST_URI} !^/?(directory1|directory2)($|/)

在目录1 |目录2 |等中放置所需数量的目录。

这应该显示为“如果REQUEST_URI不是以/ directory1或/ directory2开头。”

它将匹配:

  • / directory1 / dasdas
  • / directory1
  • / directory1 /

我想这就是你想要的。