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
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]).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.