Forum Moderators: phranque
Please try visiting
http://example.com/files/3916/print
The address bar changes to
http://example.com/getfile.php?code=3916&filename=print
How do I make the rewrite rule so that the original URL is shown on the user's address bar ?
Existing rewrite rule :
RewriteRule ^files/([^&]+)/([^&]+)/?$ http://example.com/getfile.php?code=$1&filename=$2 [L]
(This worked fine in my previous host and the original URL was shown in the addr bar)
[edited by: jdMorgan at 5:13 pm (utc) on Nov. 12, 2008]
[edit reason] Please use example.com [/edit]
That is what a rewrite does, if properly coded. It takes the requested URL and silently fetches content from an internal filepath that it does not reveal back to the browser.
You included a domain name in the target URL and that automatically turns it into a 302 redirect, as documented in the Mod_Rewrite instructions. Remove the protocol and hostname and see what you get.
The links on your site also need to use the "short" format. It is is the links that define the URLs.
Ahead of your rewrite you also need a site-wide non-www to www (or vice-versa) 301 redirect to make sure that the rewrite responds to only one of those direct URL requests, not to both.
See also very recent posts as variants of this question have been asked three other times in the last two days alone.
@jdMorgan
Thanks dude.. For enlightening me about internal and external redirects ..
[edited by: jdMorgan at 5:13 pm (utc) on Nov. 12, 2008]
[edit reason] Example.com [/edit]
One thread on WebmasterWorld has a really good title -- "Duplicate Content -- Get it Right or Perish" -- And a search of WebmasterWorld for "duplicate content" will turn up many more informative threads.
In this case, you need to choose whether the URL should or should not end in a slash, and then externally redirect the non-preferred URL to the preferred one. This decision is correctly based on whether the resource is a "file" or a directory or directory index. In HTTP, only directory or directory-index URLs should end with a slash.
The same is true for http vs. https, for example.com vs. www.example.com vs. example.com. vs. example.com:80 vs. example.com.:80 (all of which are valid hostnames), for /index.html (or php, etc.) vs. "/", for various query string parameter orders, and for many other possible URL variations -- All of these should be detected by your server and redirected to the single correct URL.
This may sound like nit-picking, but it is part of "securing your rankings" against innocent linking errors and against non-so-innocent vulnerability exploits by or on behalf of your competitors...
Jim
[webmasterworld.com...]