1

In my PHP web page I want to redirect as follows:

header("Location: page2.php?id=$tid");

The querystring is needed by page2.php, but I don't want the querystring displayed in the visitor's browser. I thought I could eliminate the querystring using mod_rewrite as follows:

RewriteEngine On
RewriteRule ^page2\.php page2\.php?

This just removes the query string for page2.php (making it behave in a way not desired), and still displays the query string in the browser's url display area.

I found other references on removing querystrings, like mod_rewrite: remove query string from URL? , but when I add redirection to the rule like [R=permanent], the url displayed by my browser goes from

localhost/admin/page2.php?id=123

with by a web page that displays just fine, to

http://localhost/C:/xampp/htdocs/admin/page2.php

where the web page is not loaded, but instead the following is displayed:

Access forbidden!

You don't have permission to access the requested object. 
It is either read-protected or not readable by the server.

If you think this is a server error, please contact the webmaster.

Error 403

localhost
9/5/2011 9:57:19 PM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1

How can I redirect to a page that needs a querystring, but hide that querystring from the visitor so that it is not displayed to them by their browser?

Cœur
  • 37,241
  • 25
  • 195
  • 267
harrije
  • 43
  • 3
  • .htaccess and mod_rewrite doesnt generally work well in localhost – swordfish Sep 06 '11 at 03:33
  • Do you have an alternate method of passing *tid* to page2.php? Secondly, URL rewriting cannot be used to modify the URL displayed in the browser. It is used to translate pretty URLs into ugly ones *internally*. – Salman A Sep 06 '11 at 06:47

1 Answers1

1

Take a look at this blog article - Apache RewriteRule and query string

Justin
  • 84,773
  • 49
  • 224
  • 367
tttony
  • 4,944
  • 4
  • 26
  • 41