#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    97
    Rep Power
    67

    htaccess rewrite


    I have this simple .htaccess file which I've used many times before without problem
    Code:
    AddDefaultCharset UTF-8
    RewriteEngine On
    RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L,R=301]
    that should take a link to this page . . .
    http://www.mysite.com/mypage

    . . . and (behind the scenes) actually look up this page . . .
    http://www.mysite.com/index.php?page=mypage

    I'm working on a site with a hosting company I've not used before and this .htaccess file doesn't work as usual. Instead it generates a 404 error message saying something like
    http://www.mysite.com/web/sites/user/0/546/225754/public/www/index.php?page=mypage does not exist

    To fix that I've changed the relative path to an absolute path so now the htaccess file reads
    Code:
    AddDefaultCharset UTF-8
    RewriteEngine On
    RewriteRule ^([^/\.]+)/?$ http://www.mysite.com/index.php?page=$1 [L,R=301]
    This works fine except the url in the browser title bar is not 'prettified' - instead of http://www.mysite.com/mypage I get http://www.mysite.com/index.php?page=mypage

    htaccess aint my thing. Hope someone can help.

    Thanks.
  2. #2
  3. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,972
    Rep Power
    9647
    Actually, your use of [R] in the first version will cause the user to be redirected to the index.php?page=mypage URL. It won't happen behind the scenes. So are you sure that is what you had in your .htaccess? Because it also does not explain the /web/sites/... URL you were seeing. It does, however, explain what is happening with the second version: having the "http://www.mysite.com" or not doesn't make a difference as long as the [R] is there.

    Try
    Code:
    RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]
    So that's what you had in the first version but without the [R].
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    97
    Rep Power
    67
    Thanks requinix - you're right - i usually do just use [L] - only included the [R] when blindly experimenting to try and make it work on new hosting company/server.

    Anyway - same thing happens with and without the [R]. Any other thoughts?

    Thanks again.
  6. #4
  7. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,972
    Rep Power
    9647
    Which "same thing"? And what else is in the .htaccess?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    97
    Rep Power
    67
    This is all thats in my htaccess file

    Code:
    AddDefaultCharset UTF-8
    RewriteEngine On
    RewriteRule ^([^/\.]+)/?$ http://www.mysite.com/index.php?page=$1 [L]
    Whether I just use [L] or include [R] the same thing happens - a link to this page
    http://www.mysite.com/mypage

    shows this page
    http://www.mysite.com/index.php?page=mypage
    in the browser title bar.

    I want it to look up that page (to make the php etc work) but show http://www.mysite.com/mypage in the browser title bar.

    Thanks again for your help.
  10. #6
  11. Headless Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,972
    Rep Power
    9647
    Drop the http:// and domain and go with just what I posted before.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    97
    Rep Power
    67
    Thanks - tried it - that's when I get this message

    The requested URL /user/0/217/159124/public/www/index.php was not found on this server.

    That's why I put the domain in there before - to bypass all those directories

IMN logo majestic logo threadwatch logo seochat tools logo