Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess重定向/abc/def/到/abc/def,但不是以/xxx/yyy/开头的URL?_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache .htaccess重定向/abc/def/到/abc/def,但不是以/xxx/yyy/开头的URL?

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/,

在.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/
,这些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中是否有其他指令?