Jump to content

[SOLVED] Rewrite half the query string


Helmet

Recommended Posts

It is possible to rewrite something like

 

example.com/index.php?foo=bar&foo2=bar2&foo3=bar3&foo4=bar4

 

to something like

 

example.com/bar/bar2/?foo3=bar3&foo4=bar4

 

I've tried with this but the page is not found:

 

RewriteRule ^(.*)/(.*)/\?foo3=$3&foo4=$4$ index.php?foo=$1&foo2=$2&foo3=$3&foo4=$4

 

Thanks in advance,

Helm

Link to comment
Share on other sites

Thanks for your reply, but adding the QSA flag still results in a 404. I'm trying to convert half of the querystring to directory structure, and keep the other half as query string. So I guess my example should have been more like:

 

RewriteRule ^(.*)/(.*)/\?foo3=(.*)&foo4=(.*)$ index.php?foo=$1&foo2=$2&foo3=$3&foo4=$4 [L,QSA]

 

Link to comment
Share on other sites

No. You don't need to specify the query string within your rewriteRule. All you need to do is specify the bits you're rewriting.

 

So if you url is like this:

example.com/bar/bar2/?foo3=bar3&foo4=bar4

 

You just need to setup your rewriteRule to match the bits highlighted above. Which is what the following rewriteRule does.

 

RewriteRule ^(.*)/(.*)/ index.php?foo=$1&foo2=$2 [L,QSA]

 

I have tested this and it works fine for me.

 

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.