SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RewriteRule doesn't behave the same way on live server

    I have a .htaccess file with the following rules

    Code:
    RewriteEngine on
    RewriteRule    ^$/index.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)/$	/$1/index.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$    /$1.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)$    /$1.php [L]
    now on localhost, this url (http://localhost/cp/landscape/) is able to be processed by the cp.php file but when I try this on the live server, this fails and the Apache server attempts to look for the index.php file in the landscape directory instead....

    After some head scratching, i found out that this url (http://www.liveserver.com/cp.php/landscape/) works.... how come? does it has something to do with the Apache config??

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    Siegen, Germany
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no rule would match for /cp/landscape/

    RewriteEngine on
    RewriteRule ^$ /index.php [L]
    RewriteRule ^([a-zA-Z0-9\-_/]+)/$ /$1/index.php [L]
    # /cp/landscape/ or /cp/landscape.htm/.html --> /cp.php
    RewriteRule ^([a-zA-Z0-9\-_/]+)/([a-zA-Z0-9\-_/]+/?|html?)$ /$1.php [L]

  3. #3
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also this:

    Code:
    RewriteRule ^([a-zA-Z0-9\-_/]+)/$ /$1/index.php [L]
    Should be this:

    Code:
    RewriteRule ^([a-zA-Z0-9\-_/]+)/?$ /$1/index.php [L]
    That way the rule doesn't break if it doesn't have a trailing slash

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    bian,
    [QUOTE=bianster]
    Code:
    RewriteEngine on
    RewriteRule    ^$/index.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)/$	/$1/index.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$    /$1.php [L]
    RewriteRule    ^([a-zA-Z0-9\-\_/]*)$    /$1.php [L]
    Caterham: Note the / in the square brackets - that does allow multiple subdirectories.

    I suspect that it's the leading slashes in the redirect (not the unnecessary escape - backslashes - in the atom's square brackets) nor the lack of space between the ^$ and /index.php in the first rule.

    Try eliminating those leading slashes in the redirections and see if that doesn't resolve your problem (it's a major difference between Windows-based test servers and Linux production [online] servers).

    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 Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the quick replies, haven't have a chance to try out the suggestions yet though

  6. #6
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=dklynn]bian,
    Quote Originally Posted by bianster
    Code:
     RewriteEngine on
     RewriteRule    ^$/index.php [L]
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)/$	/$1/index.php [L]
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$    /$1.php [L]
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)$    /$1.php [L]
    Try eliminating those leading slashes in the redirections and see if that doesn't resolve your problem (it's a major difference between Windows-based test servers and Linux production [online] servers).

    Regards,

    DK
    hi dklynn,

    i've tried removing the leading slashes in the redirect but it didn't seem to fix the problem

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

    Okay, let's start all over with the regex: What do you want to redirect and what should it be redirected to?

    From my read of your code,
    Code:
     RewriteEngine on
     RewriteRule    ^$/index.php [L]
    #1 blank => index.php BUT you've GOT to separate the $ and /!!!
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)/$	/$1/index.php [L]
    #2 redirect "everything without dots" followed by a slash
    #  to that as a subdirectory then it's index.php file
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)\.(html|htm)$    /$1.php [L]
    #3 redirect "everything without dots" as htm or html filenames
    #  to PHP scripts with the same name
     RewriteRule    ^([a-zA-Z0-9\-\_/]*)$    /$1.php [L]
    #4 redirect "everything without dots" to a php script
    # of the same name
    Were these what you were looking to do?

    That said, http://localhost/cp/landscape/ should be picked up by #2 on both servers. http://www.liveserver.com/cp.php/landscape/ should NOT (because of the dot in cp.php).

    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

  8. #8
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, actually what I want to is to have either cp.php or public.php to handle all requests that start with cp or public, eg, http://www.liveserver.com/cp/landscape/ OR http://www.liveserver.com/public/landscape/.

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

    Quote Originally Posted by bianster
    well, actually what I want to is to have either cp.php or public.php to handle all requests that start with cp or public, eg, http://www.liveserver.com/cp/landscape/ OR http://www.liveserver.com/public/landscape/.
    Okay, that's the what. What's the whereto?

    In other words, you want to redirect ^(cp|public)/(.*)$ to $1.php?something=$2 [L] if I read your reply correctly. Wanna confirm OR tell what your regex is supposed to be redirected to?

    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

  10. #10
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that was exactly what I was trying to do, thanks a lot man!

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

    Horray!

    I must be good at guessing

    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


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
  •