Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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 如何排除除一个目录之外的所有文件和目录,RewriteCond_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 如何排除除一个目录之外的所有文件和目录,RewriteCond

Apache 如何排除除一个目录之外的所有文件和目录,RewriteCond,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我想将所有非文件、非目录重定向到index.php,这样所有存在的内容都可以直接访问——除了一个目录(也应该转到index.php) 我得到的是: # Files RewriteCond %{REQUEST_FILENAME} !-f # Directories except /orderfiles/* RewriteCond %{REQUEST_FILENAME} ^/(orderfiles/)* [OR] RewriteCond %{REQUEST_FILENAME} !-d Rewri

我想将所有非文件、非目录重定向到index.php,这样所有存在的内容都可以直接访问——除了一个目录(也应该转到index.php)

我得到的是:

# Files
RewriteCond %{REQUEST_FILENAME} !-f

# Directories except /orderfiles/*
RewriteCond %{REQUEST_FILENAME} ^/(orderfiles/)* [OR]
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule .* index.php [L,QSA]
这适用于/orderfiles中的目录,但/orderfiles中的文件仍然会指向该文件。我试着加上

RewriteCond %{REQUEST_FILENAME} ^/(orderfiles/)* [OR]
RewriteCond %{REQUEST_FILENAME} !-f

但这会中断并将每个文件发送到index.php。

如果您已经接近,您需要这样的内容:

# Files
RewriteCond %{REQUEST_FILENAME} !-f

# Directories
RewriteCond %{REQUEST_FILENAME} !-d

# except /orderfiles
RewriteRule !^/?orderfiles index.php [L,QSA]

我意识到我输入了错误的内容,我的意思是“但是发送一个目录到index.php”(我编辑了我的问题以便更准确)。我确实希望/order文件被路由到index.php

那么您所拥有的是正确的,但您需要更改这一行:

RewriteCond %{REQUEST_FILENAME} ^/(orderfiles/)* [OR]
致:


你很接近,你想要这样的东西:

# Files
RewriteCond %{REQUEST_FILENAME} !-f

# Directories
RewriteCond %{REQUEST_FILENAME} !-d

# except /orderfiles
RewriteRule !^/?orderfiles index.php [L,QSA]

我意识到我输入了错误的内容,我的意思是“但是发送一个目录到index.php”(我编辑了我的问题以便更准确)。我确实希望/order文件被路由到index.php

那么您所拥有的是正确的,但您需要更改这一行:

RewriteCond %{REQUEST_FILENAME} ^/(orderfiles/)* [OR]
致:


感谢您的快速回复-我意识到我输入了错误的内容,我的意思是“但是发送一个目录到index.php”(我编辑了我的问题以便更准确)。我确实希望/orderfile被路由到index.php。谢谢!我仍然有问题(如果没有你所发布的括号,它将无法工作),所以我将^(/orderfiles/)*更改为^/new/orderfiles/,我已经重写了base/new/以上,所以我没有意识到我必须再次包含/new/。这一切都成功了。再次感谢。感谢您的快速回复-我意识到我输入了错误的内容,我的意思是“但是发送一个目录到index.php”(我编辑了我的问题以便更准确)。我确实希望/orderfile被路由到index.php。谢谢!我仍然有问题(如果没有你所发布的括号,它将无法工作),所以我将^(/orderfiles/)*更改为^/new/orderfiles/,我已经重写了base/new/以上,所以我没有意识到我必须再次包含/new/。这一切都成功了。再次感谢。