Forum Moderators: phranque

Message Too Old, No Replies

Rewrite question - which is better and why ?

URI or filepath?

         

Aveu

6:22 am on Mar 1, 2010 (gmt 0)

10+ Year Member



Hi. I will hold off asking "How do I... ?" type questions until after I have *RTFM* (Read The Forums & Manuals) but there is one thing I would like to know as I learn:

I see some examples of rewrite being used to modify the logical URI and other examples being used to rewrite the physical filepath. Is there any rationale as to why one would prefer to rewrite one of these rather than the other?

PS: If it makes any difference to the answer, I am studying mod_rewrite to be able to host multiple domains within a single account on a shared server.

g1smd

9:15 am on Mar 1, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The main SEO feature is that a 'page' of content should only be served at one URL.

It is possible for it to be served at multiple URLs: www and non-www, with and without port number, URL with parameters vs. 'SEO-friendly' URL, and any combination(s) of those and other factors.

So, the redirects 'tidy up' requests for non-canonical versions of the URL so that the correct URL is requested.

Rewrites are used to map a URL request to the internal server filepath to actually serve the content.


Example:

Wanted URL: www.example.com/shirt/2345/blue/15
Script path: /shop.php?type=shirt&id=2345&colour=blue&size=15

You would set up the rewrite to accept the URL request and rewrite to the real script location.

You would set up redirects to redirect both www and non-www URL requests containing parameters to redirect to the correct URL. You would also set up a redirect such that non-www URL requests for the 'friendly' URLs are redirected to the www version, etc.

Most importantly, pages on the site would link to the URL version that you want users to 'see' and 'use'.