Welcome to WebmasterWorld Guest from 54.166.112.74

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Remove Querystring from URL

Remove Querystring from URL

   
3:43 pm on Jan 30, 2008 (gmt 0)

5+ Year Member



I'm trying to remove the the query string from one URL if the value of one of the variables is "Password hint". Here is what I have setup in .htaccess:

RewriteCond %{query_string} Password\+hint [NC]
RewriteRule ^links\.php links.php? [L]

I only want to do this on the links.php page but it doesn't work. There are no other rewrite rules in the .htaccess and I know that Apache is reading as I tested by adding a redirect.

Any help on where I am going wrong would be appreciated.

Thanks in advance.

4:02 pm on Jan 30, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Do you have any other working rewriterules?
Have you included the Options and RewriteEngine setup directives usually required by mod_rewrite?
Do you want to redirect and change the client's address bar, or just remove the query string so that it is not passed "links.php"?

Jim

4:06 pm on Jan 30, 2008 (gmt 0)

5+ Year Member



Yes - the rewrite mod is setup correctly and if I add other rules they work fine.

I want to redirect and change the client's address bar so that the query string is not passed to "links.php".

4:32 pm on Jan 30, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Then you need an external redirect:

RewriteCond %{QUERY_STRING} Password\+hint [NC]
RewriteRule ^links\.php$ http://www.example.com/links.php? [R=301,L]

I'd also recommend 'tightening-up' that query string pattern. If Password+hint is the variable name, then use
"&?Password\+hint=" as the pattern. If it's the value, then use "=Password\+hint&?". This will prevent problems in the future if you add a new string such as "New_password+hint" or "Password+hints" -- It's best to avoid laying mines for yourself to stumble on in the future.

Jim

10:33 am on Jan 31, 2008 (gmt 0)

5+ Year Member



I'm still having problems - with the rule you posted the query string still remains. I turned on rewrite logging and I get the following:

[dkt907153/sid#26c748][rid#11d2f08/initial] (2) init rewrite engine with requested uri /portal/links2.php
[dkt907153/sid#26c748][rid#11d2f08/initial] (1) pass through /portal/links2.php
[dkt907153/sid#26c748][rid#11d2f08/initial] (3) [perdir C:/temp/htdocs/] strip per-dir prefix: C:/temp/htdocs/portal/links2.php -> portal/links2.php
[dkt907153/sid#26c748][rid#11d2f08/initial] (3) [perdir C:/temp/htdocs/] applying pattern '^links2\.php$' to uri 'portal/links2.php'
[dkt907153/sid#26c748][rid#11d2f08/initial] (1) [perdir C:/temp/htdocs/] pass through C:/temp/htdocs/portal/links2.php

It looks like its not matching on the query string. Any ideas?

Thanks

8:06 pm on Jan 31, 2008 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



No, it's not matching because the server sees the directory "/portal" ahead of links2.php, and that does not match the specified pattern. So what is "/portal"? -- You didn't mention it before.

Jim