PDA

View Full Version : Mod Rewrite for Intermediate - Apache -


seomike
06-03-2004, 04:57 PM
What we're going to do is solve the "How do I do a mod rewrite with multiple dynamic urls".

Simple. I'm going o keep this one nice and short and to the point. You should already know how to tweek your source files so you can manipulate your url out puts.

Let's say we have these three urls that are static

www.yourdomain.com/catalog.html

www.yourdomain.com/catalog/shirt-33.html

www.yourdomain.com/catalog/pants-38-32.html

What we'll have to do is set up rewrite conditions to be able to tell these things apart. A rewrite condition works like an if () statement. But we've got to use Regular Expressions to make the case of true or false.

# start mod
RewriteEngine On
Options +followsymlinks
RewriteBase /

# if catalog.html parse as catalog.php
RewriteCond %{REQUEST_URI} ^/catalog\.html$
RewriteRule ^catalog\.html$ /catalog.php [L]

# if catalog/letters-numbers.html then parse
RewriteCond %{REQUEST_URI} ^/catalog/[a-zA-Z]+-[0-9]+\.html$
RewriteRule ^catalog/([a-zA-Z]+)-([0-9]+)\.html catalog.php?item=$1&id=2 [L]

# if catalog/letters-numbers-numbers.html parse
RewriteCond %{REQUEST_URI} ^/catalog/[a-zA-Z]+-[0-9]+-[0-9]+\.html$
RewriteRule ^catalog/([a-zA-Z]+)-([0-9]+)-([0-9]+)\.html$ /catalog.php?item=$1&size=$2&length=$3 [L]

#end mod