Apache .htaccess重定向/abc/def/到/abc/def,但不是以/xxx/yyy/开头的URL?
在.htaccess中,我可以将Apache .htaccess重定向/abc/def/到/abc/def,但不是以/xxx/yyy/开头的URL?,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,在.htaccess中,我可以将/abc/def/重定向到/abc/def,删除尾部斜杠: # Redirect Trailing Slashes If Not A Folder... RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [L,R=301] 这很有效。现在,我想排除以/xxx/yyy/开头的URL,使其不被上述规则重定向,例如/xxx/yyy/12345/,
/abc/def/
重定向到/abc/def
,删除尾部斜杠:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
这很有效。现在,我想排除以/xxx/yyy/
开头的URL,使其不被上述规则重定向,例如/xxx/yyy/12345/
,这些URL需要保持原样,而不被重定向到/xxx/yyy/12345
,保留尾部斜杠
因此,我:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/xxx/yyy/
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
但它不起作用,因为
/xxx/yyy/12345/
仍被重定向到/xxx/yyy/12345
。我在这里做错了什么?使用请求
变量而不是请求
,因为请求
可能会因执行其他规则而更改:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !\s/+xxx/yyy/ [NC]
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^ %1 [L,R=301,NE]
确保使用新的浏览器进行测试。这似乎是因为我在.htaccess中有此功能:
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^ index.php [L]
RewriteRule ^(.*)$ public/$1 [L]
在上面的一个目录中。所以我要用的是:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/public/xxx/yyy/
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
在
/xxx/yyy/
之前添加/public/
,虽然公共URL实际上是/xxx/yyy/
,但似乎没有任何问题。.htaccess中是否有其他指令?