Php .htaccess-如果文件或目录不存在,则重定向
我有一个简单的CMS文件结构: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
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。您应该始终将代码粘贴到问题中,而不是链接到它。尽量少使用外部站点。