Home Modrewrite rule messes up variables
Reply: 0

Modrewrite rule messes up variables

user1062
1#
user1062 Published in June 19, 2018, 6:27 pm

I want to redirect the following example URL:

http://example.com/phone/iphone-4-vs-iphone-5/vote/123

To:

http://example.com/product.php?category=phone&p1=iphone-4&p2=iphone-5&user=123

I tried the following ModRewrite rule in my htaccess file:

RewriteRule ^(phone)/(.*)-vs-(.*)/vote/([1-9][0-9]*)$ /product.php?category=$1&p1=$2&p2=$3&user=$4 [L]

I have this in product.php file:

<?php
   echo $_GET['category'];
   echo '<br />';
   echo $_GET['p1'];
   echo '<br />';
   echo $_GET['p2'];
   echo '<br />';
   echo $_GET['user'];
 ?>

The expected output of PHP:

phone
iphone-4
iphone-5
123

The actual output I get:

phone
iphone-4
iphone-5/vote/123

Therefore the rewrite rule has something wrong so that it attaches the user variable to the p2 variable.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.449856 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO