how to add "-" character automatically to urls using htaccess or php

Discussion in 'Apache' started by Cyletech, May 5, 2011.

  1. #1
    Hi,
    I want to have urls like http://www.example.com/google-ad/star-for-you.html . i have created it before but when i use "-" character in urls, they are not found. i mean, this url (http://www.example.com/google ad/star for you.html) works but the url( http://www.example.com/google-ad/star-for-you.html) doesn't work. i wrote the htaccess code like this:
    RewriteRule ^lyrics/([0-9]+)/([^./]+)/([^./]+)\.html$ index.php?id=$1&artist=$2&song=$3
    Code (markup):
    you should know, the strings in urls are utf-8 (persian characters). how can i have urls with "-" character

    thank you
     
    Cyletech, May 5, 2011 IP
  2. MartinPrestovic

    MartinPrestovic Peon

    Messages:
    213
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think your missing the hypen in your first character class. Your second and third should be okay as your using the period to match and if I recall correctly that will match the hypen, so give this one a try:

    
    RewriteRule ^lyrics/([-0-9]+)/([^./]+)/([^./]+)\.html$ index.php?id=$1&artist=$2&song=$3
    
    Code (markup):
     
    MartinPrestovic, May 6, 2011 IP