SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RewriteRule not working

    Hello there!

    I am having a problem with rewriterule,
    None of this works, and I know the file htaccess works etc.. Can anyone help, I changed \ to / etc..
    My htaccess
    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^cover-([0-9]+)/.html$ view.php?cover=$1
    RewriteRule ^sendcover-([0-9]+)/.html$ send_cover.php?cover=$1
    RewriteRule ^index\.html$ index.php
    RewriteRule ^page-([0-9]+)/.html$ page.php?pid=$1
    RewriteRule ^success\.html$ index.php?er=success
    RewriteRule ^unknown-error/.html$ index.php?er=un_error
    RewriteRule ^width/.html$ index.php?er=width
    RewriteRule ^height/.html$ index.php?er=height

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,060
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    The only thing really wrong with those rules is that /.html should really be \.html
    With / it is never going to work, since that will literally match a slash in the URL.
    The reason you use \. instead of . in the URL is that in regular expressions . matches any character. Unless you "escape" it with a \ to take away that special meaning so it just matches a dot.

    1) Do you know on which version of Apache you are? If you are on 1.x (highly unlikely since it's very old), you need to start of the RewriteRules with ^/ instead of just ^
    2) If you rewrite to (for the first rule) /view.php?cover=$1 instead of view.php?cover=$1, does it work then? (probably not, but on some hosts adding a leading slash fixes things -- more specifically, on hosts that use Mass Virtual Hosting)
    3) You should add [L] at the end of all of those rules to tell Apache to stop matching once it's found a match. This won't fix anything for you, but it will make the code more efficient (once it works)

    If none of that fixes it you should probably check if mod_rewrite is enabled in the first place (by either checking yourself if you have admin access to the server, or asking your hoster if you don').
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    May 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would like to thank you so much for your help, that indeed worked and I am so grateful for your help through this.
    I followed all your simple steps and voila, it worked.
    Thanks again! If there's anything I can do for you, please state so

  4. #4
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,258
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    The only thing really wrong with those rules is that /.html should really be \.html
    With / it is never going to work, since that will literally match a slash in the URL.
    The reason you use \. instead of . in the URL is that in regular expressions . matches any character. Unless you "escape" it with a \ to take away that special meaning so it just matches a dot.
    Great catch!

    Quote Originally Posted by ScallioXTX View Post
    If you are on 1.x (highly unlikely since it's very old), you need to start of the RewriteRules with ^/ instead of just ^
    I wanted to clear this part up real quick, because this has been spreading around the forums. Both Apache 1.x and Apache 2.x actually behave in exactly the same way with regard to the leading slash. See my full explanation, which contains references to the documentation and repeatable steps to verify this behavior.
    "First make it work. Then make it better."

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,060
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    I wanted to clear this part up real quick, because this has been spreading around the forums. Both Apache 1.x and Apache 2.x actually behave in exactly the same way with regard to the leading slash. See my full explanation, which contains references to the documentation and repeatable steps to verify this behavior.
    Huh, I've spreading wrong information for a few years now it would seem (although it probably doesn't matter much since no-one has been using Apache 1.x for ages, I hope!). Thanks for putting my head straight

    @dklynn ; should read this too, as I'm pretty sure he's making the same mistake I am.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Rémon,

    Naw, that was a MAJOR difference when Apache 2 came out. If things have changed as Jeff suggests, then it's a recent development. That said, anyone using Apache 1 must be using an ancient version (no reason not to update to Apache 2) and Apache 2 has declined to match the leading /.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  7. #7
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,258
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    If things have changed as Jeff suggests, then it's a recent development.
    The per-server and per-directory behavior is in the documentation at least as far back as Apache 1.3. I even installed 1.3 to test it (you could do the same). This isn't a recent development. It's always been this way.
    "First make it work. Then make it better."


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
  •