Jump to content

rewrite rule for form with query parameters


Omzy

Recommended Posts

Generally speaking a RewriteRule would do the opposite of what you describe, it would take the 'neat' URL and  call the 'ugly' URL, thus masking the crappy address. Obviously to achieve this would require a lot of messing about with regards to changing the current workings of your site. This may be useful.

Link to comment
Share on other sites

" it would take the 'neat' URL and  call the 'ugly' URL"

 

Well yeah, that's exactly what I'm trying to do here. I've done this for normal links on my site, but this is for a form. By default a GET form appends query parameters to it's ACTION URL, for example even if my form URL was: http://localhost/mysite/search/ then if I submit that form I get something like http://localhost/mysite/search/?company=Microsoft, but I'd rather have http://localhost/mysite/search/Microsoft

 

I want the ugly URL turned into a nice URL. :)

Link to comment
Share on other sites

Well yeah, that's exactly what I'm trying to do here.

Actually your trying the exact opposite of that, this is a common thing that seems to trip people up, including myself. The link I provided should give you the framework for getting the URL in the users browser to appear as http://localhost/mysite/search/Microsoft instead of as http://localhost/mysite/search/?company=Microsoft you then need to decide what to do from there. You will probably have to make another RewriteRule to forward this new address back to the old one, but as a proxy rather than redirect. I'm not entirely sure how you can do this without causing a loop. I may experiment, if I work it out I'll get back to you.

Link to comment
Share on other sites

I tested this on index.php in the root folder...

 

RewriteCond %{QUERY_STRING} ^company=([a-zA-Z0-9]+)$
RewriteRule ^index\.php$ /search/%1? [R=301]
RewriteRule ^search/([^/]+)/? /index.php?search=$1 [L]

 

The first rule redirects the URL in the users browser and the second passes the new URL back to the original page on the server side without the user being aware.

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.