Forum Moderators: phranque

Message Too Old, No Replies

Mod rewrite SIMPLE

New guy trying to grasp how to do simple rewrite task

         

Eleethal

6:58 pm on Nov 27, 2006 (gmt 0)

10+ Year Member


Im not trying to redirect or anything, I simply want to edit the url that apepars in the browser address bar without using an error handler, only mod_rewrit commands.

ie www.site.com/product_info.php?products_id=116&osCsid=763513de109cf66b5c88186802d1db2d
to
www.site.com/product/WhateverIChose.html&osCsid=763513de109cf66b5c88186802d1db2d

Anyone have any clue cuz Ive been busting my head for 4 days reading manuals and tutorials with little to no avail.

jdMorgan

7:40 pm on Nov 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post your best effort so we can discuss it.

For more information, see the policies and documents cited in our forum charter [webmasterworld.com].

You will need the concepts of "back-reference" and the use of RewriteCond %{QUERY_STRING} to start.

Jim

Eleethal

4:16 am on Nov 28, 2006 (gmt 0)

10+ Year Member



RewriteEngine on
RewriteRule product/name1.html ^product/28$
RewriteRule product/name2.html ^product/29$
RewriteRule product/name3.html ^product/30$
RewriteRule product/name4.html ^product/31$

To my reading, this should take site.com/product28 and change the url in the address bar to /product/name1.html while still loading the data from product/28/

jdMorgan

3:27 pm on Nov 28, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code is ill-formed, and the concept won't work anyway.

The only ways to change the URL in the browser address bar are to either redirect the client or to change the links on your pages. This latter approach is what most Webmasters want to do.

The links published on your pages are what show in the browser address bar.

The usual point of confusion about this is the assumption that mod_rewrite is an "output content modifier" -- that it somehow modifies the content of pages being sent back to the browser. But mod_rewrite does not do this. Instead it acts just after a request is received by the server, and does one of three things: It either changes the internal server filepath associated with a requested URL, issues a redirect or error response to the client, or performs a proxy throughput to a different server. This all happens during the URL-to-filename translation phase of the Apache API, before any content is served and before any scripts are invoked.

So the usual approach to change the URL in the address bar goes like this:

  • Change the link URL on your page(s).
  • Internally rewrite the URL of that link, when requested by the client, to the correct path on the server.
  • (Optional) Redirect (only) direct client requests for the old URL to the new one in order to correct search engine listings more quickly. This last step is a bit tricky, and I'd encourage you to get the rest working first.

    For more information on a problem closely related to this one, see this thread [webmasterworld.com] in our Apache Forum Library.

    Jim

  •