I have a strange problem using .htaccess RewriteEngine.
I have this simple rule:
RewriteEngine On
RewriteRule ^(.\*)/(.\*).php$ pages/test.php?lang1=$1&page1=$2 [L]
In pages/test.php I put this php code:
echo('lang: '.$_GET['lang1'].'< br />');
echo('page: '.$_GET['page1'].'< br />');
echo('querystring: '.$_SERVER['QUERY_STRING']);
So, when calling http://test.local/en-US/something.php, I would expect something like:
lang: en-US
page: something
querystring: lang1=en-US&page1=something
Instead, this is the weird output I get from the page:
lang: pages
page: test
querystring: lang1=pages&page1=test
Can someone help me out?
You get that result because you created a loop, try using these lines :
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/pages/test\.php$
RewriteRule ^(.*)/(.*)\.php$ /pages/test.php?lang1=$1&page1=$2 [L]
You can also use the QSA flag:
RewriteRule ^(.*)/(.*).php$ pages/test.php?lang1=$1&page1=$2 [QSA,L]
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
http://httpd.apache.org/docs/current/rewrite/flags.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With