Sergiu Svet
Sergiu Svet

Reputation: 101

mod_rewrite: Help to rewrite an URL

I have a website and I'm trying to rewrite it's url.

It's pretty simple, but i'm not understanding how to do it.

The pages are the next ones:

http://localhost/site/index.php?p=home, etc. home is a parameter, and rewrite should be like this: http://localhost/site/home.html

http://localhost/site/section.php?id=someid and i want it to be like http://localhost/site/the-name-of-the-section-from-database-SOMEID

http://localhost/site/product.php?id=someid and i want it to be like http://localhost/site/category-name/product-name-SOMEID

I think it's simple, but I still don't understand how to do it. Please, help me.

Thanks!

Upvotes: 1

Views: 367

Answers (3)

kirca
kirca

Reputation: 46

http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/ use this link in has a detail ehplanation about mod_rewrite.also i think anubhava got the regex right

Upvotes: 0

mumin aydin
mumin aydin

Reputation: 63

this page shoul help you .htaccess Url Rewrite Generator. it generates htaccess files for you.

Upvotes: 0

anubhava
anubhava

Reputation: 784908

Put these lines in your ROOT .htaccess:

Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteRule ^site/(home)\.html/?$ site/index.php?p=$1 [L,QSA,NC]

# Assuming hyphen is not in the section name
RewriteRule ^site/.*-(.*)/?$ site/section.php?id=$1 [L,QSA,NC]

# Assuming hyphen is not in the product name
RewriteRule ^site/[^/]*/.*-(.*)/?$ site/product.php?id=$1 [L,QSA,NC]

Upvotes: 2

Related Questions