Apache 将所有文件重定向到子目录中的index.php
我在/var/www/v1和/var/www/v2下有一个网站。在v2文件夹中,我有一个.htaccess文件,其代码如下:Apache 将所有文件重定向到子目录中的index.php,apache,mod-rewrite,Apache,Mod Rewrite,我在/var/www/v1和/var/www/v2下有一个网站。在v2文件夹中,我有一个.htaccess文件,其代码如下: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php?request=$1 重写规则在v2文件夹下不起作用,但是如果我把它和文件放在/var/www/目录下,就可以了 例如,我有以下文件: upload.php display.php index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?request=$1
重写规则在v2文件夹下不起作用,但是如果我把它和文件放在/var/www/目录下,就可以了
例如,我有以下文件:
upload.php
display.php
index.php
当我访问website.com/v2/display/时,它抛出一个404,说“请求的URL/v2/display/在此服务器上找不到。”您可以尝试禁用多视图:
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /v2/index.php?request=$1 [L]
我将其更改为
RewriteRule^(.*)$/v2/index.php?request=$1
,现在可以使用,但如果文件存在,则不能使用。例如,如果我调用website.com/v2/something
,它会将其指向index.php,请求=something。如果我去website.com/v2/display
我会得到404,说文件不存在。