How do I include hyphens in a htaccess regex?

  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 01, 2007
  • Posts: 315
  • Status: Offline

Post June 15th, 2010, 10:50 am

I am currently rewriting URLs with a htaccess file to create cleaner URLs. Here is my htaccess file:

Code: [ Select ]
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)/$ /page.php?s=$1
RewriteRule ^([a-zA-Z0-9]+)$ /page.php?s=$1
  1. Options +FollowSymlinks
  2. RewriteEngine on
  3. RewriteRule ^([a-zA-Z0-9]+)/$ /page.php?s=$1
  4. RewriteRule ^([a-zA-Z0-9]+)$ /page.php?s=$1


With this regex I am able to have URLs like:

Code: [ Select ]
http://mysite.com/foobar


But I also want URLs like:

Code: [ Select ]
http://mysite.com/foo-bar


How do I edit the regex to include a hyphen when needed?
Joe Hall
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 15th, 2010, 10:50 am

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 3415
  • Loc: Richland, WA
  • Status: Offline

Post June 15th, 2010, 11:04 am

For your pattern just add a hyphen,

Code: [ Select ]
[a-zA-Z0-9-]
#define NULL (::rand() % 2)
  • RedBMedia
  • Proficient
  • Proficient
  • User avatar
  • Joined: May 01, 2007
  • Posts: 315
  • Status: Offline

Post June 15th, 2010, 1:26 pm

Thanks a ton Spoof! For your hospitality. Samuele L Jackson is pleased.


Image
Joe Hall

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 234 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.