Forum Moderators: phranque
Currently my website shows a link like this (link 1) http://www.example.com/proddetailbs.php?prod=ASA-09-FAR-AIM
Instead, I would like it to show (link 2) http://www.example.com/Books-Software/ASA-09-FAR-AIM/
I used the mod_rewrite rule:
RewriteRule ^Books-Software/(.*)/ proddetailbs.php/?prod=$1
This will forward anyone who types in link (2) to link (1). However, I would like the reverse to happen also: If someone types in link (1), I want only the link (2) URL to be shown (the link 2 page does not actually exist).
Also, there is a directory issue when the user types in link (2). Since some of the pictures on link (1) are relative links, it doesn't properly open them because of the directory sign in the URL. Is there any way to get around this besides making all of the links absolute?
Thanks!
[edited by: coopster at 1:18 pm (utc) on Mar. 12, 2009]
[edit reason] please use example.com in code [/edit]
Further, redirecting every single incoming request for these dynamic URLs to their static equivalents would result in two client HTTP requests for each page loaded, slowing down the "user experience" and trashing your "site stats."
The short version of the correct procedure is to:
1) Change your on-page links to SEO-friendly static form
2) Use your internal rewrite rule above to rewrite incoming requests for "friendly" URLs to the proper script filepath+query
3) Optionally, externally redirect incoming client requests (only) for the old dynamic URLs to the new static URLs
However, optional step 3 is a fix-up to speed search engines' re-indexing of your URLs, to preserve the functionality of old bookmarks and old links from sites that you don't control, and to prevent duplicate-content problems in search ranking. It cannot practically be used without doing the other two steps first.
If you "move" your query-string parameters into "directory levels" in your static URLs, then you can expect problems with page-relative links; It is the browser which resolves relative links, by using the "directory" that it "sees" in its address bar. To prevent problems, use server-relative or canonical links on your pages, e.g. <img src="/images/logo.gif"> or <img src="http://example.com/images/logo.gif"> instead of page-relative links.
For more information on this subject, see Changing Dynamic URLs to Static URLs [webmasterworld.com] in our Apache Forum Library [webmasterworld.com].
Jim
[edited by: jdMorgan at 1:38 pm (utc) on Mar. 12, 2009]