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 如果文件不存在,则重定向到文件并保留url_.htaccess - Fatal编程技术网

.htaccess 如果文件不存在,则重定向到文件并保留url

.htaccess 如果文件不存在,则重定向到文件并保留url,.htaccess,.htaccess,我在以下文件夹中有一个index.php: https://example.com/folder1/folder2/index.php 如果URL是 https://example.com/folder1/folder2/93j3h233j3 然后重定向到index.php,但URL应该保持不变 我的想法是:我先调用一个没有.php的php文件,然后尝试重定向 RewriteRule ^folder1/folder2/([^\.]+)$ /folder1/folder2/index.php?

我在以下文件夹中有一个index.php:

https://example.com/folder1/folder2/index.php
如果URL是

https://example.com/folder1/folder2/93j3h233j3
然后重定向到index.php,但URL应该保持不变

我的想法是:我先调用一个没有.php的php文件,然后尝试重定向

RewriteRule ^folder1/folder2/([^\.]+)$ /folder1/folder2/index.php?&%{QUERY_STRING}

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^folder1/folder2/(.*)$   /folder1/folder2/index.php? [R=302]
这不管用。 保留这个名字!但是怎么做呢? 有什么想法吗


谢谢

您的规则如下:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(folder1/folder2)/.+$ $1/index.php [L,NC]

无需使用您的第一条规则。

您的规则如下所示:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(folder1/folder2)/.+$ $1/index.php [L,NC]
没有必要使用你的第一条规则