Best unofficial Apache Server developers community
Username
Forgot password?
Sign in with Twitter account
Sign in with Facebook account

Tricky mod_rewrite challenge

1

47 views

Fraternal greetings StackOverflowers.. 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 using meaningful URLs like this one on Amazon

http://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 http://domain.com/contact.php, that I don't want to redirect to the records page.

Thank you! Fred

asked June 25, 2011 2:30 am CDT
posted via StackOverflow

1 Answer

0
 

Try this in your root's .htaccess:

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

http://example.com/foo-bar/42 will be rewritten to http://example.com/records.php?id=42

It wont affect URLs like contact.php, since it does not match ^[^/]+/(\d+)$

answered June 25, 2011 3:23 am CDT

Your answer

Join with account you already have


Sign in with Twitter account
Sign in with Facebook account
Sign in with Google Friend Connect

Preview
Similar questions
Help with mod_rewrite
February 10, 2011
Mod_rewrite help
May 28, 2011
Mod_rewrite help
March 25, 2011
Mod_rewrite help
March 28, 2011
Mod_rewrite help
February 10, 2011
Mod_rewrite help
May 26, 2011
Mod_Rewrite for CDN
January 25, 2011