Kristian
Kristian

Reputation: 1363

Dynamic url rewriting htaccess

I have a problem with dynamic url rewriting.

I have two different kind of url’s that I need to rewrite for SEO purposes. Since these are not fixed, but dynamic – I can’t just setup rules in htaccess as usual. In addition I also have a couple of fixed URL's.

All slug names are unique, and are stored in two different tables in my database.

  1. Product names (I have a very large list of products) http://www.domain.com/a-big-brown-bear.html (should point to view_product.php)

  2. Categories (The categories can be in two levels) http://www.domain.com/cars/ford.html http://www.domain.com/cars.html

(These should point to view_category.php, and both level of menu names should be sent along)

What’s the best way of controlling dynamic urls, while still relying on htaccess? Possible someone knows a class to use?

PS: My problem is not really writing the rules, but how to fetch the rules from my DB into htaccess.

I’m afraid I’m making this more complicated that it really is. All help is appreciated!

Thanks in advance,

Regards

Upvotes: 4

Views: 1093

Answers (1)

Pekka
Pekka

Reputation: 449395

You have essentially two options:

  • Catch all incoming requests (except for images, style sheets, etc.) into a server-side front controller (PHP, ASP or whatever server-side language you use), and do the redirection there using header(....). This is the easiest and most popular way.

  • Use Apache's RewriteMap directive to frequently write your maps into text files that mod_rewrite can look up.

The RewriteMap alternative might be beneficial in special omptimization scenarios with lots of traffic. Usually, chances are you're well off with the first option.

Upvotes: 2

Related Questions