.htaccess file

Hey,

I have just started using .htaccess files for SEO friendly links.

Now i understand the general principle, for example this line:


RewriteEngine on
RewriteRule ^homepage$ index.php [L]

Means change index.php to homepage…

But i have another question. I have a list of categories (12) and they will all go to a page with a link like this:

items.php?ID=1
items.php?ID=2
.
.
.
.
items.php?ID=12

Now how can i write some code in the .htaccess which will make this to:

items/1

This looks a lot better i think, and plus i will need the ID. Would i need to write 12 lines of code in the .htaccess file? I can see a problem with this, as in the admin section eventually i will add more categories, so i don’t want to have to keep adding more lines in the .htaccess if you know what i mean?

Any ideas?

Thanks :slight_smile:

Everything you need to know is in this page.


RewriteEngine on
RewriteRule ^items/([0-9/]+)$ items.php?ID=$1 [L]

untested


RewriteEngine on
RewriteRule ^/item/([0-9]{1,2})$ item.php=$1 [L]

That will cover any items between 0-99.


RewriteEngine on
RewriteRule ^/item/([0-9]+)$ item.php=$1 [L]

That will cover any items between 1-infinity.

Note that the range of 0 to 9 can be expressed by \d rather than [0-9], for example:

RewriteRule ^/item/(\\d+)$ item.php?ID=$1 [L]

Cups,

:tup: Spot on!

BTW, codegirl86 asked a good question late last night about forcing port 80 causing browser warnings so I’ve updated that mod_rewrite tutorial.

BM,

You forgot the key for ID’s value.

Billy,

PLEASE think of mod_rewrite as redirecting TO the old format from your new format. That will make it easier to get your head around the regex and redirection of your mod_rewrite statements.

Regards,

DK