Send address through .htaccess to get shorter URL?

Discussion in 'PHP' started by le007, Sep 15, 2007.

  1. #1
    Hey all,

    how can I parse a long dynamic url through .htaccess and get a short url result plz? :cool: :) :confused:
     
    le007, Sep 15, 2007 IP
  2. Rogem

    Rogem Peon

    Messages:
    171
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    An Apache Rewrite is what you mean, for example:

    
      RewriteEngine on
     
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      
      RewriteRule ^page([/]?)$ page.php
      RewriteRule ^page/query/([0-9]+)([/]?)$ page.php?query=$1 [QSA]
    
    Code (markup):
    Put something like the above into your .htaccess and you should be fine :)
     
    Rogem, Sep 15, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Rogem, those RewriteCond's are only necessary when you have patterns that could potentially match existing files, such as images, but other than that, that code seems fine. You might want to add [L] flags and ([/]?) can be written as /?

    le007, can you show us an example of one of your dynamic URLs you want to shorten?
     
    krt, Sep 15, 2007 IP
  4. le007

    le007 Well-Known Member

    Messages:
    481
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    le007, Sep 16, 2007 IP
  5. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #5
    htaccess doesn't create those rewritten URLs, it only parses them back to the 'original'.

    To create the links in the first place you have to do it yourself (either by just hardcoding the SEF URLs or writing a function to create them).
     
    TwistMyArm, Sep 16, 2007 IP