【发布时间】:2019-06-18 00:40:52
【问题描述】:
我正在使用 .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]
【问题讨论】:
-
我有点 hack 和 slash 与 mod-rewrite,但试一试:
RewriteRule ^(directory1|directory2)($|/) - [L] -
我应该把它放在哪里?我把它放在上面的代码之前和之后,它没有效果。目录仍然转到 m。
-
在
# Check if this looks like a mobile device.行上方看起来是最好的地方,如果它不起作用,我会尝试你可以在谷歌上搜索的几百种变体之一 -
在那里尝试过,同样的事情。那就是问题所在。找不到一个有效的。