TwelvestoneBack End

regular expression question -->


Sign in

  • Waiting for Godot ( 730 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 5.1 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.9 k posts )
    general front end design an...
  • Back End ( 9.7 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Mac8myPC
 
2011-06-01

So i'm working on some mod_rewrite stuff for a new website... I've got this to work

URL -http://www.somesite.com/listings/my-test-listing-222.html

rewriterule listings/([/]+).html$ listings.php?listingID=$1

but I really just want the numbers... so i tried this

listings/([0-9]+).html$ listings.php?listingID=$1

The first one works.. the second one yields up a 404.. :(

poliguin
 
2011-06-01

listings/([a-z-]+)([0-9]{1,}).html listings.php?listingID=$2

Adjust what is in bold for what it is that you want to allow in a URL string. Right now it'll just allow a-z and -

Mac8myPC
 
2011-06-01

wow.. thx.

so.. is the reason mine didn't work because I wasn't allowing for the text before the numbers?

poliguin
 
2011-06-01

You were basically accepting everything up until the .html to be passed in on your rewrite rule for listing id. With the rewrite rules you'll want to compound expressions a bit to get the match. they take a decent amount of playing around with to get it right.

Technomancer
 
2011-06-02

This is a useful little tool for testing your .htaccesshttp://htaccess.madewithlove.be/

Mac8myPC
 
2011-06-02

I ended up going with this..

URL -http://www.somesite.com/listings/this-listing-22/242.html RewriteRule listings/([A-Za-z0-9-]+)/([0-9]+).html$ listings.php?title=$1&ID=$2

I found that with your expression if there was a number in the name.. it would screw it up. I still don't understand regular expressions at all... but I really appreciate the help. k

poliguin
 
2011-06-02

That is the safer way to go. But yes, the expression i put in there would be listings + (any letter and a "-") + (any number 1 or more times) + .html

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneBack End

regular expression question -->