views:

127

answers:

4

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

+3  A: 

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

RewriteRule ^/test/ /test/default.php
Konrad Rudolph
A: 

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.

Ken
A: 

I’d use:

RewriteCond %{REQUEST_URI} ^/([^/]*/)*
RewriteRule !/default\.php$ %0default.php [L]
Gumbo
A: 
RewriteRule ^/test(/.*)?$ /test/default.php [L]

Access the original URI, if needed, in the $_SERVER global array.

Judging by your original, you probably want:

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