Jump to content

htaccess rewrite and GET variables


asgsoft

Recommended Posts

I am trying to get variables from URLs, rewritten by htaccess and which are passed on using GET.

 

At the moment I have:

 

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^eating-out.php?sort=(.+)&page=(.*)$ dev1.php?cat=1&sort=$1&page=$2

 

Which is getting me a 404 error page when I access eating-out.php.. meaning the page isn't found.

 

However, if I use this:

 

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^eating-out.php dev1.php?cat=1

 

And try and access eating-out.php?page=2 it won't work.. the value of $_GET['page'] is still nothing.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/201394-htaccess-rewrite-and-get-variables/
Share on other sites

A RewriteRule only matches against the REQUEST_URL, which doesn't include the QUERY_STRING, therefore the later part of your Rule can never match. If you need to only match certain patterns then you can use RewriteCond however given the pattern you have there you probably don't need to do that. You only seem to be passing over the same GET variables with one extra one, as such you should be able to use something like this...

 

RewriteRule ^eating-out.php$ /dev1.php?cat=1 [QSA]

 

If it isn't working try adding in a R flag so you can see where the page is being direct to, this will help you to debug (change the bit at the end to [QSA,R=302]).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.