2

I have an existing htaccess that works fine:

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

I wish to modify this so that all urls that start with /test/ go to /test/default.php.

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

4

4 回答 4

3

Basically, just put /test/ in front of your expression. Also, the parentheses are unnecessary here:

RewriteRule ^/test/ /test/default.php
于 2008-11-27T18:13:59.143 回答
0

If you need to pass on information from the URL you can capture it (with parentheses) and send it to default.php (with $1) as follows:

RewriteRule ^/test/(.*)$ /test/default.php/$1

so that http//..../test/foo/bar/ would result in /test/default.php/foo/bar/ . Your script can then access the extra information.

于 2008-11-27T18:22:40.857 回答
0

我会使用:

RewriteCond %{REQUEST_URI} ^/([^/]*/)*
RewriteRule !/default\.php$ %0default.php [L]
于 2009-01-15T14:10:33.317 回答
0
RewriteRule ^/test(/.*)?$ /test/default.php [L]

如果需要,访问 $_SERVER 全局数组中的原始 URI。

从您的原件来看,您可能想要:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^/test(/.*)?$ /test/default.php [L]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ /default.php
于 2009-03-17T18:00:35.800 回答