1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Apache htaccess

Discussion in 'PHP & Perl' started by sonic1234, Jan 11, 2012.

  1. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    Hello BHW,

    i have a php website and it pulls data from mysql database.

    i have urls like :
    Code:
    http://mydomain.com/video.php?name=video+name&id=1&tag=video-tag
    i want it in this form:
    Code:
    http://mydomain.com/video-tag/video-name-id.html
    What should i write in .htaccess to do this.

    Thanks :)
     
  2. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
  3. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    No it doesnt work, (i have + in between url, how to make those + to -)

    thanks anyways.
     
  4. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    Ok i got the solution. :D
    here it is:


    Code:
    RewriteRule ^(.*)/(.*)-id(.*).html video.php?id=$3
     
  5. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    Good :) It wasn't hard to rewrite... (sorry about the above. haven't used apache/htaccess in a long time).

    Here's what you should do though:

    Code:
    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule ^(.*)/(.*)-(.*)-(.*)\.html$ video.php?name=$2+$3&id=$4
    That way you'll be doing what you wanted:

    Code:
    http://mydomain.com/video-tag/video-name-id.html
    
    e.g. http://mydomain.com/video-tag/myvideo-xpwizard-88134.html
     
    • Thanks Thanks x 1
    Last edited: Jan 11, 2012
  6. sonic1234

    sonic1234 Junior Member

    Joined:
    Oct 19, 2009
    Messages:
    131
    Likes Received:
    25
    Occupation:
    Webmaster
    Location:
    Equinox
    Thanks Man, i am new to Apache :D

    but why have you added a $ after .html here:

    Code:
    Options +FollowSymLinks 
    RewriteEngine on  
    RewriteRule ^(.*)/(.*)-(.*)-(.*)\.html$ video.php?name=$2+$3&id=$4
    
     
  7. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    ^ = start of string
    $ = end of string

    It's just regex basics.