views:

76

answers:

2

I am trying to use SEO-friendly URLs for a website. The website displays information in hierarchical manner. For instance, if my website was about cars I would want the URL 'http://example.com/ford' to show all Ford models stored in my 'cars' table. Then the URL 'http://example.com/ford/explorer' would show all the Ford Explorer Models (V-6, V-8, Premium, etc).

Now for the question: Is mod_rewrite used to rewrite a query string style URL into a semantic URL, or the other way around? In other words, when I use JavaScript to set window.location=$URL, should the URL be the query string version 'http://example.com/page.php?type=ford&model=explorer' OR do I internally use 'http://example.com/ford/explorer' which then gives me access to the query string variables?

Hopefully, someone can see my confusion with this issue. For what it's worth, I do have unique 'slugs' made for all my top level categories (obviously, the site isn't about cars).


Thanks for all the help so far. I got the rewrite working but it is affecting other paths on the site (CSS, JavaScript, images). I using the correct path structure for all these includes (ie '/images/car.png' and '/css/main.css'). Do I have to use an absolute path ('http://example.com/css/main.css') for all files? Thanks!

+2  A: 

once you have set up mod_rewrite then your links should point to the mod_rewritten version of the URL (in your example: http://mysite.com/ford/explorer). Internally in your system you will still reference the variables as if they are traditional query string name value pairs though.

Its also worth pointing out that Google is now starting to advocate more logical URLs from a search engine point of view, i.e. a query string over mod rewrite

Does that mean I should avoid rewriting dynamic URLs at all? That's our recommendation, unless your rewrites are limited to removing unnecessary parameters, or you are very diligent in removing all parameters that could cause problems. If you transform your dynamic URL to make it look static you should be aware that we might not be able to interpret the information correctly in all cases http://googlewebmastercentral.blogspot.com/2008/09/dynamic-urls-vs-static-urls.html

also worth looking at: http://googlewebmastercentral.blogspot.com/2009/08/optimize-your-crawling-indexing.html

seengee
bmb
i guess i have always looked at it the other way round without necessarily thinking about the exact semantics, not sure which one is strictly true but both make sense to me.
seengee
I see why the OP is confused. Different people refer to it different ways.
bmb
+2  A: 

Generally, people who use mod_rewrite use the terminology like this:

I want mod_rewrite to rewrite A to be B.

What this means is that any request from the outside world for page A gets rewritten to file B on the server.

You want the outside world to see URLs that look like

A) http://example.com/ford/explorer

but your web server wants them to look like

B) http://example.com/page.php?type=ford&model=explorer

I would say you want to rewrite (A) to look like (B), or you want to rewrite the semantic URL into a query string URL.

Since all the links on your page are clicked on by the user and/or requested by the browser, you want them to look like (A). This includes links that javascript uses in window.location. They can and should look like (A).

bmb