0

我有一个可以正常工作的现有 htaccess:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (.*) /default.php 
DirectoryIndex index.php /default.php

我希望对此进行修改,以便所有以 /test/ 开头的 URL 都转到 /test/default.php,同时将所有其他 URL 保留为现有的 /default.php

示例:http ://www.x.com/hello.php --> http://www.x.com/default.php示例:http ://www.x.com/test/hello.php -- > http://www.x.com/test/default.php

4

5 回答 5

1

将 /test/ 的规则放在其他所有规则之前,但[L]如果匹配,则给它一个标志以停止那里的重写规则处理。

于 2008-12-01T17:37:36.003 回答
0

Try this.

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

RewriteRule /test/.* /test/default.php 
RewriteRule .* /default.php 

DirectoryIndex index.php /default.php

You also don't need the ()'s because your not setting the value as a variable.

于 2009-06-24T17:44:06.007 回答
0

In your main folder, use the following .htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule .* default.php [L]
DirectoryIndex index.php default.php

In your ./test/ folder (I assume it is a physical folder), copy and paste the same .htaccess file.

First, you didn't need the / at the beginning of default. Apache will always assume it is looking in the same directory as the .htaccess file is located.

Second, Apache looks backwards when looking for an .htaccess file. So anything in ./test/.htaccess will overwrite what's written in ./.htaccess.

于 2009-06-24T17:49:43.097 回答
0

尝试这个

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (/test/)?(.*) $1/default.php 
DirectoryIndex index.php /default.php
于 2008-12-01T17:57:20.550 回答
0

这应该有效:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (test/)?(.*) $1default.php [L]
DirectoryIndex index.php /default.php
于 2008-12-01T18:04:23.017 回答