SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple mod_rewrite question??

    Hi there

    I wanted to redirect urls such as www.domain.com/folder
    or
    www.domain.com/folder/

    to a file:
    display.php?category=folder

    I have managed to do this with mod_rewrite, however I dont know how to deal with the case if there is no trailing slash..

    Here is what I used

    RewriteRule ^([a-z]*)/$ display.php?category=$1

    I just need a way to direct them to the same place whether they use a trailing slash or not.....

    Any help is greatly appreciated....

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RewriteRule ^([a-z]*)/?$ display.php?category=$1

    In regular expressions, the question mark makes the previous character optional.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2001
    Posts
    439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey thanks again randem......

    That works fine for the folder structure, but if I use that and then type the domain name.....
    ie: www.domain.com, that is also being redirected to the display.php.....

    How would I get around that........

    cheers

  4. #4
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    RewriteRule ^/([a-z]*)/?$ display.php?category=$1

    Okay, now there's a slash required at the front of the URI.

    I'm not sure if mod_rewrite starts from the domain name or from the URI, having never used it myself. If it starts from the domain name, you could use this:

    RewriteRule ^www.yoursite.com/([a-z]*)/?$ display.php?category=$1


    Curious, though... does this redirect the browser, or does it rewrite at the server? Seems to me that if it were redirecting the browser, you'd get a never-ending loop of redirection.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •