Reputation:
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, while keeping all other URLs with the existing /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
Upvotes: 0
Views: 2557
Reputation: 95334
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
.
Upvotes: 0
Reputation: 3252
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.
Upvotes: 0
Reputation: 1374
This should work:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (test/)?(.*) $1default.php [L]
DirectoryIndex index.php /default.php
Upvotes: 0
Reputation: 54854
Try this
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (/test/)?(.*) $1/default.php
DirectoryIndex index.php /default.php
Upvotes: 0
Reputation: 1434
Put the rule for /test/ in before the rule for everything else, but give it an [L]
flag to stop the rewrite rule processing there if it matches.
Upvotes: 1