Mobile app version of vmapp.org
Login or Join
Angie530

: Tricky mod_rewrite challenge I list about 9,000 records on my little site. At the moment I'm showing them with a dynamic page, like http://domain.com/records.php?id=019031 But I'd like to start

@Angie530

Posted in: #Apache #CleanUrls #ModRewrite #Redirects #Url

I list about 9,000 records on my little site. At the moment I'm showing them with a dynamic page, like
domain.com/records.php?id=019031

But I'd like to start using meaningful URLs like this one on Amazon
www.amazon.co.uk/Library-Mythology-Oxford-Worlds-Classics/dp/0199536325

where the title string on the root level gets ignored and requests are redirected to the records.php page, which accepts the ID as usual.

Does anybody know how I could achieve that with mod_rewrite? I'm wondering how I'd deal with requests to my other root-level pages, like domain.com/contact.php, that I don't want to redirect to the records page.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Angie530

1 Comments

Sorted by latest first Latest Oldest Best

 

@Connie744

Try this in your root's .htaccess:

RewriteEngine on
RewriteRule ^[^/]+/(d+)$ records.php?id= [QSA]

example.com/foo-bar/42 will be rewritten to example.com/records.php?id=42
It wont affect URLs like contact.php, since it does not match ^[^/]+/(d+)$

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme