You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bob <bo...@gmail.com> on 2015/05/21 14:23:42 UTC

[users@httpd] Removing query string through .htaccess

Hello All,

I have already gone through a no. of links for removing query strings and till now all are going back to domain.
The one I'm using presently is

``````````````
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ /? [R=302,L]

`````````````````````

As obvious the above goes back to homepage, but is there any rule set which just remove the query string and keep the url intact ?

like http://mywxample.com/any_page/?xyz should be changed as http://mywxample.com/any_page

Any help is very much appreciated.

with regards,
Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: Removing query string through .htaccess

Posted by Kurtis Rader <kr...@skepticism.us>.
On Thu, May 21, 2015 at 10:02 PM, Bob <bo...@gmail.com> wrote:

> Thanks for your kind response. I have tried your rule sets but
> unfortunately it is working as before.
>
> i.e. http://mydomain.com/page1/?xyz and http://mydomain.com/page1?xyz
> both redirect to http://mydomain.com


My guess is that you still have a broken rule in your config from earlier
attempts to get this working. Perhaps you've attempted to do this redirect
via a .htaccess file and httpd.conf and forgotten that a broken rule is
still in effect in one of those files.

Also, how are you testing this? Do you have a UNIX like system you can work
with? If so I would recommend hand-crafting the request and using the nc
command to issue it. That gives you maximum control and makes it easy to
see exactly what the web server is returning. For example, I created a file
name "g.req" with the following contents then ran ```nc localhost 80 <
g.req``` from a terminal window. Note that the last line of the file is an
empty line.

```
GET /hello.php?action=register HTTP/1.1
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64;
Trident/5.0
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Content-Length: 0
Host: www.skepticism.us
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://www.skepticism.us/wp-login.php
Cookie: wordpress_test_cookie=WP+Cookie+check

```

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

[users@httpd] Re: Removing query string through .htaccess

Posted by Bob <bo...@gmail.com>.
Hello Kurtis,

Thanks for your kind response. I have tried your rule sets but unfortunately it is working as before.

i.e. http://mydomain.com/page1/?xyz and http://mydomain.com/page1?xyz both redirect to http://mydomain.com


> On Fri, May 22, 2015 at 1:47 AM, Kurtis Rader <kr...@skepticism.us> wrote:
> On Thu, May 21, 2015 at 6:18 AM, Bob <bo...@gmail.com> wrote:

> I'm also successful with following but goes to home page, can't preserve the actual link

> RewriteCond %{THE_REQUEST} \?[^\ ]+
> RewriteRule (.*) /$1? [R=302,L]

> Works for me. Although I would write the rule like this

> RewriteCond %{QUERY_STRING} !=""
> RewriteRule ^ %{REQUEST_URI}? [R=302,L]

> When I issue a "GET /hello.php?whatever=1" with either version I get a 302 response with

> Location: http://www.skepticism.us/hello.php

> Also, if you don't want to match non-whitespace I recommend \S rather than [^\ ].

> -- 
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank

> On Thu, 21 May 2015 13:18:49 +0000
> Bob <bo...@gmail.com> wrote:

> 
> I'm also successful with following but goes to home page, can't preserve the actual link
> 
> 
> RewriteCond %{THE_REQUEST} \?[^\ ]+
> RewriteRule (.*) /$1? [R=302,L]
> 
> 
> On Thu, 21 May 2015 12:23:42 +0000
> Bob <bo...@gmail.com> wrote:
> 
> > Hello All,
> > 
> > I have already gone through a no. of links for removing query strings and till now all are going back to domain.
> > The one I'm using presently is
> > 
> > ``````````````
> > RewriteCond %{QUERY_STRING} .
> > RewriteRule ^$ /? [R=302,L]
> > 
> > `````````````````````
> > 
> > As obvious the above goes back to homepage, but is there any rule set which just remove the query string and keep the url intact ?
> > 
> > like http://mywxample.com/any_page/?xyz should be changed as http://mywxample.com/any_page
> > 
> > Any help is very much appreciated.
> > 
> > with regards,
> > Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: Removing query string through .htaccess

Posted by Kurtis Rader <kr...@skepticism.us>.
On Thu, May 21, 2015 at 6:18 AM, Bob <bo...@gmail.com> wrote:

>
> I'm also successful with following but goes to home page, can't preserve
> the actual link
>
> RewriteCond %{THE_REQUEST} \?[^\ ]+
> RewriteRule (.*) /$1? [R=302,L]


Works for me. Although I would write the rule like this

RewriteCond %{QUERY_STRING} !=""
RewriteRule ^ %{REQUEST_URI}? [R=302,L]


When I issue a "GET /hello.php?whatever=1" with either version I get a 302
response with

Location: http://www.skepticism.us/hello.php

Also, if you don't want to match non-whitespace I recommend \S rather than [^\
].

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

[users@httpd] Re: Removing query string through .htaccess

Posted by Bob <bo...@gmail.com>.
I'm also successful with following but goes to home page, can't preserve the actual link


RewriteCond %{THE_REQUEST} \?[^\ ]+
RewriteRule (.*) /$1? [R=302,L]


On Thu, 21 May 2015 12:23:42 +0000
Bob <bo...@gmail.com> wrote:

> Hello All,
> 
> I have already gone through a no. of links for removing query strings and till now all are going back to domain.
> The one I'm using presently is
> 
> ``````````````
> RewriteCond %{QUERY_STRING} .
> RewriteRule ^$ /? [R=302,L]
> 
> `````````````````````
> 
> As obvious the above goes back to homepage, but is there any rule set which just remove the query string and keep the url intact ?
> 
> like http://mywxample.com/any_page/?xyz should be changed as http://mywxample.com/any_page
> 
> Any help is very much appreciated.
> 
> with regards,
> Bob

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org