SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RewriteRule help needed

    Hi all,

    This should be a really easy one, but for some reason I keep getting 404's.

    .htaccess:
    Code:
    AddDefaultCharset UTF-8
    RewriteEngine on
    RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)$ index.php?var=$4
    The site is running under a subdirectory called /site/ on root and the .htaccess file is in there as well.

    The full url to trigger this would be something like:
    http://www.example.com/site/somevar1...somevar3/32145


    So basically all this will trigger index.php?var to be 32145


    What the ____ am I doing incorrectly?
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    smf,

    That looks okay to me. Have you confirmed that mod_rewrite's enabled and usable via .htaccess? If not, check the tutorial linked in my signature.

    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

  3. #3
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for taking a look dklynn.

    For a second there I thought that mod_rewrite wasn't actually enabled, but the host has confirmed that it actually is and still the rewrite doesn't do anything!

    Which means there's something wrong with the actual RewriteRule line.
    However to me it looks correct!?!?

    Anything else you can see?
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    smf,

    Yes, you've not accounted for "site/" in your regex (assuming this is in the .htaccess in the DocumentRoot).

    FWIW (not much), the - in a range definition is supposed to be the first character to avoid confusion over whether it's a meta character or not. That said, I've never seen a case where having it in the last position causes any confusion (for mod_rewrite) so this is just a "word to the wise."

    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

  5. #5
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @DK,

    The site is running under a subdirectory called /site/ on root and the .htaccess file is in there as well.
    The contents of everything including the .htaccess is in the /site/ directory, which means I shouldn't add the "site/" into the regex, not that I havn't tried though! :P
    ..I've tried all combos and nothing at all works, it's just too odd. I'm beginning to think it's the actual server config now so will run some tests on another setup elsewhere to concur with these thoughts.

    Thanks for your thoughts on the matter however!
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  6. #6
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    smf,

    Put this in the DocumentRoot (above sites) and remove the code from your sites directory:
    Code:
    RewriteEngine on
    RewriteRule ^sites/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)$ sites/index.php?var=$4 [R=301,L]
    When you're satisfied that this has resolved your problem, remove the R=301 which was there only to show you that the redirection has taken place as intended.

    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 Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @DK,

    Would you believe that didn't work either!
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,605
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    smf,

    No. There must be something which we're overlooking by assuming that it's working.

    I've probably already asked but have you run the test to verify that mod_rewrite is enabled (from the tutorial article linked in my signature)? Creating the three files and testing should take no more than 10 minutes.

    Are you sure you're on an Apache 2.x server?

    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

  9. #9
    SitePoint Evangelist smftre's Avatar
    Join Date
    Dec 2008
    Location
    London
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @DK,

    After much head-ache, it seems it was a permissions thing, which I might add is much harder to find out when running mod_rewrite on a shared host where you don't have access to all the logs.

    Think it has been resolved now. (notice that first word there <--["think"]- )

    Thanks for your swift responses.
    Statvoo.com The Website Traffic Monitor
    The best way to monitor traffic to your sites for free!


    Web Development London UK We make web 3.0 applications


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
  •