Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 重写条件以排除特定目录_.htaccess - Fatal编程技术网

.htaccess 重写条件以排除特定目录

.htaccess 重写条件以排除特定目录,.htaccess,.htaccess,我曾经有一个单独的移动/m目录(服务于m.example.com),但已经将所有这些文件合并到主站点中 我已经为所有移动的文件设置了重定向,这些文件工作正常。但是,根目录中不再存在一个目录/games,我希望在请求到达根目录之前停止对该目录的请求(例如,m.example.com/games/game1.php) 在空的m/目录(只有.htaccess和ErrorDocument)中,我首先有以下内容: 重写规则^games/-[L,R=404] 如果没有它,请求将在根域上生成一个无限循环。在我

我曾经有一个单独的移动/m目录(服务于m.example.com),但已经将所有这些文件合并到主站点中

我已经为所有移动的文件设置了重定向,这些文件工作正常。但是,根目录中不再存在一个目录/games,我希望在请求到达根目录之前停止对该目录的请求(例如,m.example.com/games/game1.php)

在空的m/目录(只有.htaccess和ErrorDocument)中,我首先有以下内容:

重写规则^games/-[L,R=404]

如果没有它,请求将在根域上生成一个无限循环。在我看来,这应该完全停止请求,但事实并非如此

那么,我有

RewriteCond%{REQUEST\u URI}^游戏[NC]
重写规则(.*)https://www.example.com/$1[R=301,L]

我希望请求在第一行完成,
RewriteRule^games/-[L,R=404]
,但它目前正在进行:

->->

因此,它正确地将请求标记为404,将其发送到自定义404,但不会停止。最后的重定向仍在将其发送到主站点,而主站点没有
my-custom-404-page-on-m.php
,因此返回404

我试过很多其他的组合,比如

RewriteCond%{REQUEST\u URI}^\/游戏[NC]

RewriteCond%{REQUEST\u URI}^游戏。*[NC]

RewriteCond%{REQUEST\u URI}^游戏\/[NC]

但它们都给出了相同的结果


我怎样才能让失败的请求停止在“m”域中,而不转到主站点?

好的,所以我找到了答案

我最后的
RewriteCond
应该指向文件
My-custom-404-page-on-m.php
,而不是
/games
目录

此外,它仍然需要
游戏
目录的
重写规则

“m”域中
.htaccess
的完整解决方案:

# Even though this directory does not exist, need to include this:
RewriteRule ^games/ - [L,R=404]

# Send ordinary pages on their way, except for the ErrorDocument
RewriteCond %{REQUEST_URI} !^/my-custom-404-page-on-m\.php$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]

# Catch any games/ directory 404 cases here
ErrorDocument 404 /my-custom-404-page-on-m.php