remove input image querystring co-ordinates with htaccess

Ask your mod_rewrite and Redirection questions here, and get answers!

remove input image querystring co-ordinates with htaccess

Postby maniac » 04 Sep 2008 22:32

I have a form like this:
Code: Select all
<form method="get">
<input type="image" src="button.jpg" name="button" value="1" />
</form>

When you click on the button and submit the form, the resultant url is:
Code: Select all
/mypage.php?button=1&button.x=3&button.y=4

I want to use htaccess to remove the co-ordinates from the querystring to leave:
Code: Select all
/mypage.php?button=1

Can anybody help?

Thanks.
maniac
 
Posts: 3
Joined: 04 Sep 2008 22:19

Re: remove input image querystring co-ordinates with htaccess

Postby mod_rewrite » 12 Sep 2008 05:42

maniac wrote:When you click on the button and submit the form, the resultant url is:
Code: Select all
/mypage.php?button=1&button.x=3&button.y=4

I want to use htaccess to remove the co-ordinates from the querystring to leave:
Code: Select all
/mypage.php?button=1


Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /mypage\.php.*\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} button\. [NC]
RewriteRule ^mypage\.php$ /mypage.php? [C]
RewriteRule .* /mypage.php?button=1 [R,L]
mod_rewrite
 
Posts: 102
Joined: 30 Oct 2006 19:55

Re: remove input image querystring co-ordinates with htaccess

Postby maniac » 12 Sep 2008 08:17

Thank you for your reply. I don't quite understand it, but from the looks of it, button=1 is hard coded. I was hoping to retain the value of whatever button was set to in the querystring (and any other querystring variables). So rather than simply replacing the entire querystring with button=1, I want to remove the button.x and button.y part and leave the rest as it is.

In fact, this would be more useful if it worked on any url too (not just mypage.php).

Sorry if I wasn't very clear or have mis-understood your solution.
maniac
 
Posts: 3
Joined: 04 Sep 2008 22:19

Re: remove input image querystring co-ordinates with htaccess

Postby mod_rewrite » 12 Sep 2008 13:49

maniac wrote:Thank you for your reply....Sorry if I wasn't very clear or have mis-understood your solution.


maniac, your clarification was close to perfect, very nice.. so here is some working code that I think does everything you want.

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /.*\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} button\.(x|y) [NC]
RewriteCond %{QUERY_STRING} (.*)(button\.[xy]{1}=[0-9]+.?button\.[xy]{1}=[0-9]+.?)(.*) [NC]
RewriteRule .* %{REQUEST_URI}?%1%3 [R,L]
mod_rewrite
 
Posts: 102
Joined: 30 Oct 2006 19:55

Re: remove input image querystring co-ordinates with htaccess

Postby maniac » 12 Sep 2008 18:58

Awesome!

This looks great. And it even makes sense to me!

Cheers mod_rewrite - you're my hero...
maniac
 
Posts: 3
Joined: 04 Sep 2008 22:19

Re: remove input image querystring co-ordinates with htaccess

Postby stefan42 » 27 Nov 2008 23:42

I've found this topic very helpful in my htaccess research lately. It's been a rough path. I apologize for bringing this topic back from the dead but I have a very similar problem to maniac's and I haven't been able to solve it.

I tried everything that mod_rewrite suggested, especially the part that interested me :

Code: Select all
Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteCond %{THE_REQUEST} ^GET\ /mypage\.php.*\ HTTP/ [NC]
RewriteCond %{QUERY_STRING} button\. [NC]
RewriteRule ^mypage\.php$ /mypage.php? [C]
RewriteRule .* /mypage.php?button=1 [R,L]


I got that part to work, but it wasn't exactly what I wanted to do, so I tried to adapt the code so the rest of the URL (including the other query strings) would be preserved.

Basically, I wanted page.php?article=12&sort=desc to redirect to page.php?article=12 .

This might sound easy to do but right now I'm about to lose my mind with this. The architecture of my site is ready for this change but I'm really stuck with this. Any help would be greatly appreciated.
stefan42
 
Posts: 1
Joined: 27 Nov 2008 23:33


Return to Redirect or Rewrite Questions



Who is online

Users browsing this forum: clerkfurniture, HIBcokyacrornsap, ShakhtarrDon, VocrepeAcceby, Zitioutbava