gpt4 book ai didi

regex - RewriteCond 排除不工作的路径

转载 作者:行者123 更新时间:2023-12-04 00:40:56 24 4
gpt4 key购买 nike

我想要这个网址:

http://www.example.com/path/antyhing

不被重定向。

这是我所拥有的不起作用的东西:
RewriteCond %{REQUEST_URI} !^/path/.*$ [NC]
RewriteRule ^ http://m.example.com/ [R,L]

目前它将所有 URL 重定向到 http://m.example.com/
这是我的 .htaccess 文件中的完整代码:
RewriteBase /
RewriteEngine On

# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

# Skip next rule if mobile=0
RewriteCond %{QUERY_STRING} (^|&)mobile=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 to make sure we haven't set the cookie before
RewriteCond %{HTTP:Cookie} !\mobile=0(;|$)
# Don't redirect "path" pages
RewriteCond %{REQUEST_URI} !^.+?/path/.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.example.com/ [R,L]

最佳答案

你能用这个替换你的最后一条规则吗:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

# Check if mobile=1 is set and set cookie 'mobile' equal to 1
RewriteCond %{QUERY_STRING} (^|&)mobile=1(&|$)
RewriteRule ^ - [CO=mobile:1:%{HTTP_HOST}]

# Check if mobile=0 is set and set cookie 'mobile' equal to 0
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$)
RewriteRule ^ - [CO=mobile:0:%{HTTP_HOST}]

# Skip next rule if mobile=0 [OR] if it's a file [OR] if /path/
RewriteCond %{QUERY_STRING} (^|&)mobile=0(&|$) [OR]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_URI} ^.*/path/.*$
RewriteRule ^ - [S=1]

# Check if this looks like a mobile device
RewriteCond %{HTTP_PROFILE} !^$ [OR]
RewriteCond %{HTTP_X_WAP_PROFILE} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
# Check if we're not already on the mobile site
RewriteCond %{HTTP_HOST} !^m\.
# Check to make sure we haven't set the cookie before
RewriteCond %{HTTP_COOKIE} !mobile=0(;|$)
# Don't redirect "path" pages
RewriteCond %{REQUEST_URI} !^.*/path/.*$ [NC]
# Now redirect to the mobile site
RewriteRule ^ http://m.example.com/ [R,L,NC]

OP 编辑​​:唯一的问题来自 %{REQUEST_URI}出于我不明白的原因,它仅适用于 ^.*/path/.*$

关于regex - RewriteCond 排除不工作的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18871314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com