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
Php .htaccess-如果文件或目录不存在,则重定向_Php_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Php .htaccess-如果文件或目录不存在,则重定向

Php .htaccess-如果文件或目录不存在,则重定向,php,.htaccess,mod-rewrite,redirect,Php,.htaccess,Mod Rewrite,Redirect,我有一个简单的CMS文件结构: application/ data/ src/ web/ .htaccess index.php 如果文件或目录存在,我想将所有请求重定向到/index.php execep,然后我想将所有请求重定向到/web。 例子: 到index.php/ 到web/images/logo.png 现在我的.htaccess看起来是:试试这个 RewriteEngine on RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCo

我有一个简单的CMS文件结构:

application/
data/
src/
web/
.htaccess
index.php
如果文件或目录存在,我想将所有请求重定向到/index.php execep,然后我想将所有请求重定向到/web。 例子: 到index.php/ 到web/images/logo.png

现在我的.htaccess看起来是:

试试这个

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ /web [L]

RewriteRule ^.*$ index.php [L]
第一条规则将捕获任何可以映射到现有文件或目录并重写到web文件夹的请求。第二条规则(不带rewritecond)将捕获剩余的并重写th index.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ /web [L]

RewriteRule ^.*$ index.php [L]

第一条规则将捕获任何可以映射到现有文件或目录并重写到web文件夹的请求。第二条规则(不带rewritecond)将捕获剩余的并重写th index.php

您只需将代码更改为如下所示

改变这个

RewriteCond %{REQUEST_URI} !^/index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [NC,L]
RewriteRule ^(/)?$ index.php [L]
对此

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /web/index.php [L]

RewriteRule ^(.*)$ index.php [NC,L]

您只需要更改代码,使其看起来像这样

改变这个

RewriteCond %{REQUEST_URI} !^/index.php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php [NC,L]
RewriteRule ^(/)?$ index.php [L]
对此

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteRule ^(.*)$ /web/index.php [L]

RewriteRule ^(.*)$ index.php [NC,L]

不,因为如果文件存在,我需要将directory/web设置为main。您应该始终将代码粘贴到问题中,而不是链接到它。尽量少使用外部站点。不,因为如果文件存在,我需要将directory/web设置为main。您应该始终将代码粘贴到问题中,而不是链接到它。尽量少使用外部站点。