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
https://forums.phpfreaks.com/topic/152831-solved-rewrite-half-the-query-string/
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]

 

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.

 

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.