RewriteEngine On
RewriteRule ^$ /index.phtml [R,L]
RewriteRule ^index.phtml.+$ /index.php$1 [R,L]
I have 2 urls like https://www.example.com/index.phtml
and https://www.example.com/index.php
which both point to very different sites. I want to redirect to index.php
in case there are any parameters found after index.phtml
.
For example, https://www.example.com/index.phtml?a=b
should go to https://www.example.com/index.php?a=b
(second rule). I am trying the above rules but the second one isn’t matching (the first rule works fine). Thanks for any help/suggestions
Please ask if you need any more details.
2
Answers
With your shown samples, please try following .htaccess rules file. Please make sure that your htaccess file and index.php are present in same folder.
Also make sure to clear your browser cache before testing your URLs.
You may use this code in site root .htaccess:
Note that
QUERY_STRING
get automatically appended to target URL so/index.phtml?a=b
will be redirected to/index.php?a=b
.Make sure to clear your browser cache before testing this change.
Once you verify it is working fine, replace
R=302
toR=301
. Avoid usingR=301
(Permanent Redirect) while testing your redirect rules.