.htaccess 如果文件不存在,则重定向到文件并保留url
我在以下文件夹中有一个index.php:.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?
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]
没有必要使用你的第一条规则