Htaccess Two different redirects

I have an existing htaccess that works great:

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

      

I want to change this so that all urls starting with / test / go to /test/default.php while keeping all other urls with the existing /default.php .

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

0


source to share


5 answers


Place the rule for / test / in before the rule for everything else, but give it a flag [L]

to stop processing the rewrite rule there if it matches.



+1


source


try it



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

      

0


source


This should work:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule (test/)?(.*) $1default.php [L]
DirectoryIndex index.php /default.php

      

0


source


Try it.

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 () because you are not setting the value as a variable.

0


source


In the 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 folder ./test/

(I will assume it is a physical folder) copy and paste the same file .htaccess

.

At first you didn't need the /

default start. Apache will always assume that it is looking in the same directory as the file .htaccess

.

Second, Apache looks backward when looking for a file .htaccess

. So, something in ./test/.htaccess

will rewrite written in ./.htaccess

.

0


source







All Articles