Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 13 of 13
  1. #1
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP 404 and htaccess problem.

    Hi. Wondering if anyone out there can help me, as I have spent hours reading and can't find a solution.

    I have added Mod Rewrite to my htaccess file. And have a custom 404 page.

    Which is all working fine, but the 404 error page loads the template twice, where as if it is from a HTML file it only loads once.

    Is there a way I can make the htaccess only require the template once?

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Can you post your htaccess contents?

    Likely you have some kind of loop going on. Maybe you need to add [L] to signify the LAST directive. Or something.

  • #3
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the response. Okay, here it is. The variable $1 is the page content that loads into a php template. I think that that must be the issue, because when a link from a PHP page is broken it loads the double header from the template, but when a link comes from a HTML file it just shows regular black text with no template. But I did already try making a static file, but to no avail.




    RewriteEngine on
    RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

    ErrorDocument 404 http://www.******.net/staging/page/not-found

  • #4
    $object->toCD-R(LP); vinyl-junkie's Avatar
    Join Date
    Jun 2003
    Posts
    3,073
    Thanks
    2
    Thanked 22 Times in 22 Posts
    You might want to also post your 404 page code, as there might be something wrong there.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more
    SNAP to it!

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Well I should confess there is a large voodoo aspect to this stuff -- it even says so in the official docs! But here are my thoughts. They are just guesses:

    1. try putting the 404 line first?
    2. does the 2nd question mark need to be escaped (probably not but worth a try)?
    3. I would think the slashes should be escaped too -- but you said that part is workiing ok?

  • #6
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You might want to also post your 404 page code, as there might be something wrong there.

    No, that page is just a content page, the template is generated from index.php?page=not-found This may seem like a silly question but you mentioned there was some voodoo involved, does the title of the doc need to be 404?

    I will try some of those other suggestions though I think I have already tried things like moving it up to first position. Thanks for the suggestions.

  • #7
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And yes bustamelon the mod rewrite is working fine...

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tommy2toes
    And yes bustamelon the mod rewrite is working fine...
    OK. So where does PHP come in?
    It may *still* help to see your 404 page. Is there an include() statement somewhere? What if you change that to include_once()? If the ErrorDocument target is itself a PHP file, then the rewrite rule is being processed twice. Again, put the ErrorDocument line first, then the rewrite rule.

  • #9
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <div id="Text">
    <?php @ require_once ("$page.html"); ?>
    </div>

    This is the php that is on my main index.php page. I has other html header and footer, but I know that all this is working smoothly, and a link looks like this:

    <li id="home"><a href="http://www.********.net/staging/page/about"></a>


    The 404 page just has text and is called into $page like every other page. I think you are right about it being called twice or being rewritten twice. I think that is the issue. There must be like a refresh command or a reload command for the htaccess doc...? or am I off here?

  • #10
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tommy2toes
    The 404 page just has text and is called into $page like every other page. I think you are right about it being called twice or being rewritten twice. I think that is the issue. There must be like a refresh command or a reload command for the htaccess doc...? or am I off here?
    I hate to be a broken record, but I suggested twice that you rearrange your .htaccess file so that the ErrorDocuiment directive is on top, followed by the rewrite stuff. Did you try that, and what was the result?

    Not sure what you're getting at with the refresh stuff? It gets looked at on every request, and should never be cached or anything, so a save is all taht's necessary when you edit it.

  • #11
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I will try some of those other suggestions though I think I have already tried things like moving it up to first position. Thanks for the suggestions.

    I did try it before if you go back and read the post. Anyways, I tried that again, but to no avail, same result. Thanks for the suggestions.
    Last edited by tommy2toes; 05-01-2006 at 06:14 PM.

  • #12
    New to the CF scene
    Join Date
    Apr 2006
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    One other thing I find interesting, is I can't use relative links anymore because of the rewrite I believe, I wonder if this has anything to do with it.

  • #13
    Regular Coder
    Join Date
    Mar 2006
    Location
    Connecticut, USA
    Posts
    400
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Still struggling with this?
    Can we assume it's your Regex now?
    Can you explain as clearly as possible what your pattern matching is intended to do?

    RewriteRule ^page/([^/\.]+)/?$ index.php?page=$1 [L]

    It looks to me like it's looking for a URL that starts with "page", followed by a forward slash, then it takes anything after that that IS NOT a forward slash or a dot, all the way up until it finds the LAST forward slash, preceded by a question mark at the very end of the URL.

    I could be wrong but it seems like that RE is a bit confusing. What possibilities exist for the requested URI? Is it always going to be a single word where $1 is? If so, what if you did something like this:

    RewriteRule ^page/(.*)/$ index.php?page=$1 [L]


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •