SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Slight .htaccess Problem

    I have the following code in my .htaccess file for my website.

    PHP Code:
    RewriteEngine on
    RewriteBase 
    /
    RewriteRule ^([A-Za-z_0-9-]+)((/)|())$ redirect.php?user=$
    Now let me explain. I basically host a blog site for a few friends of mine and I make it possible for users to view their blog by visiting www.website.com/username instead of having to go to www.website.com/redirect.php?user=username.

    The only problem with this is if somebody types in 'www.website.com/username/' instead of 'www.website.com/username' they will get a 404 error.

    I seemed to have made some strides with the code, if I enter, for example, 'www.website.com/myusername/' it will redirect me to: http://www.website.com/myusername/re...ser=myusername instead of just http://www.website.com/redirect.php?user=myusername

    I think I'm really close. How should I modify the .htaccess code to alleviate the problem with the extra slash at the end?

    Thanks in advance!

    -influx

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    Code:
    RewriteEngine on 
    RewriteRule ^([A-Za-z_0-9-]+)/?$ redirect.php?user=$1

  3. #3
    SitePoint Evangelist Will Kelly's Avatar
    Join Date
    May 2005
    Location
    London
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Additionally there's a good comment on php.net about POSIX regex's.

    http://uk.php.net/manual/en/ref.regex.php#19555

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey all,

    I tried changing it to the following:

    RewriteEngine on
    RewriteBase /
    RewriteRule ^([A-Za-z_0-9-]+)((/)|())?$ redirect.php?user=$1


    I even tried adding a / in front of redirect.php to call for the home directory.

    None of this seems to work for me. If i type in www.website.com/username/ it will still redirect to http://www.website.com/username/redi...?user=username.

    What could be wrong? Could it be my server?
    Thanks guys!


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
  •