如何从文件夹重写网址?

时间:2014-08-19 18:38:32

标签: .htaccess

如何重写所有请求

FROM / folder1 / folder2 /%any-request或page% TO /folder1/folder2/index.php

我无法理解如何从规则中排除其他网址。

RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ folder1/folder2/index.php [NC,L]

2 个答案:

答案 0 :(得分:0)

您的RewriteCond有点偏离。

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-s [OR]
RewriteCond %{REQUEST_FILENAME} !-l [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder1/folder2/.*$ folder1/folder2/index.php [NC,L]

答案 1 :(得分:0)

您可以将此规则与否定前瞻性正则表达式一起使用:

RewriteEngine On

RewriteRule ^(folder1/folder2)/(?!index\.php).*$ $1/index.php [NC,L]