SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod re write rules breaks php include() function

    Hello forums

    I have this strange problem with my mod rewrite rules. It used to be working without a hitch , then recently it is breaking my site most particularly the php include function.

    example:

    rule:
    RewriteRule ^contents/([A-Za-z0-9-]+)/?$ index.php?page=contents&perma=$1 [NC,L]

    url:
    http://www.baguiotrader.com/contents...-baguio-trader

    it gives me these errors:


    Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/baguio/public_html/contents.php on line 4

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/baguio/public_html/contents.php on line 4

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/baguio/public_html/contents.php on line 5

    Fatal error: Call to a member function set() on a non-object in /home/baguio/public_html/contents.php on line 10

    But when I use this url it works fine:

    http://www.baguiotrader.com/index.ph...-baguio-trader

    Is there a server misconfiguration somewhere? I know htaccess is working, bec if it's not then it should be throwing me 404 errors. Then again it used to be working ...

    Any ideas? Thanks
    Don't Panic

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

    Obviously, it's the redirection which is causing the problems. What about all the other "support files?" From what you've provided, I'd HAVE to guess that your include using a relative link and your redirection is changing the directory level (which it is). Use the <base> tag in your index.php script which is shown in my signature's tutorial.

    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 stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello DK,

    this is whats on my index file:


    Code PHP:
    define(__ROOT,$_SERVER['DOCUMENT_ROOT']);
    define(__TEMPLATES,__ROOT.'/templates/');
    define(__ENGINE_CORE, __ROOT.'/core/');
    array_walk(glob(__ENGINE_CORE.'*.php'),create_function('$v,$i', 'return require_once($v);')); 
     
    $page = $_GET['page'];
     
    if ($page =='contents'){
    include 'contents.php';
    }else{
    //do home page codes here
    }

    when you say base tag do you mean:

    Code PHP:
    include '/contents.php';
    Don't Panic

  4. #4
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically all files in the core directory is required once with this:

    array_walk(glob(__ENGINE_CORE.'*.php'),create_function('$v,$i', 'return require_once($v);'));
    Don't Panic

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

    Did you even look at the tutorial's examples?

    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

  6. #6
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes you said to use the base tag

    <base http://www.site .com /external file />

    however, how can I use the base tag with the include function?

    Anyway it is so weired the error sudenly disappeared at least for me, but when my client opened the site the error is there eeeekk.... I don't know what to do I guess I'll just have to abandon mod re writes for a while
    Don't Panic

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

    The <base> tag is used to tell the browser (where relative links are referenced to). On second thought, it should not matter to a PHP include() as that should be relative to the script's location.

    In other words, I don't believe that there is anything wrong with your mod_rewrite.

    Okay, after another look, consider:
    Code:
    RewriteRule ^/?contents/([-A-Za-z0-9]+)/?$ index.php?page=contents&perma=$1 [R=301,L]
    Here, I've added the /? after the start anchor as you haven't specified Apache 1 or 2 (this will work on both where your start anchor only version will only work with Apache 2).

    I'd eliminate the optional trailing /, too, as that can cause "support file" problems (with relative links).

    Finally, the No Case flag is already accounted for by your atom's range definition. This flag is really (IMHO) only useful with the {HTTP_HOST} variable which is not case sensitive. I've replaced it with R=301 so you can TEST that the redirection is taking place (remove it when you're satisfied it works).

    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 Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks dklynn

    It didn't work. There is really something wrong with the server configuration of my hosting. Just now I checked and some items were missing on the database oh Jeez I hate that webhost

    Anyway my rules works on my local host. I tried it on other webhosts and it also works. So I guess it's time to switch host.

    Thanks again you look great

    Cheers!
    Don't Panic

  9. #9
    SitePoint Zealot webhost.uk.net's Avatar
    Join Date
    Jan 2009
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by stonedeft View Post
    thanks dklynn

    It didn't work. There is really something wrong with the server configuration of my hosting. Just now I checked and some items were missing on the database oh Jeez I hate that webhost

    Anyway my rules works on my local host. I tried it on other webhosts and it also works. So I guess it's time to switch host.

    Thanks again you look great

    Cheers!

    Opps thats bad.. Normally the error you are getting can be fixed by your web hosting provider.

  10. #10
    SitePoint Evangelist stonedeft's Avatar
    Join Date
    Aug 2009
    Posts
    589
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by webhost.uk.net View Post
    Opps thats bad.. Normally the error you are getting can be fixed by your web hosting provider.
    Not with this webhosting. It will take them about 2 months to answer open tickets in their customer service area and usually they will take them another month blaming the client for this instead of fixing it...I'm not kidding if you want to know what webhost I'm talking about give me a PM and google a lot of their disgruntled cleints
    Don't Panic


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
  •