SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    My new rewrite breaks my forum login?

    I would post this in the original thread http://www.sitepoint.com/forums/show...es-code-please - which would help future users much more - but someone closed it. Here is the code Jeff gave me. Works perfect except it prevents me from loging into my forum backend for some reason. Took me 15 hours to figure that out. OMG. I tried to give a exclusion to the forum folder but I must not of been doing it right because I couldnt get it to work.

    So two questions? Why would this break my forum login? And two, can I make it exclude the forum located at www.site.com/forum/? Doing so I would assume all would function correctly again. FYI using my old and much larger rewrite the login works. Thanks.

    Code:
    # Rewrite index.html/php to folder
    RewriteRule ^(.*/)?index\.(html?|php)$ /$1 [R=301,L]
    
    # Rewrite non-www (non-canonical) to www
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

  2. #2
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,270
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Without being able to see or reproduce the issue, my best guess is that somewhere the forum POSTs to an index.php page, and when it's redirected to strip index.php out of the URL, then the POST data is lost... But that's only a guess.

    If you want to exclude your forum section from these rewrite rules, then this condition should suffice.

    RewriteCond $1 !^forum(?:$|/)

    This would go in front of each of the two rewrite rules. Keep in mind that this might not be the best solution, but without being able to troubleshoot, I can't even be certain of the problem.
    "First make it work. Then make it better."

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    Without being able to see or reproduce the issue, my best guess is that somewhere the forum POSTs to an index.php page, and when it's redirected to strip index.php out of the URL, then the POST data is lost... But that's only a guess.

    If you want to exclude your forum section from these rewrite rules, then this condition should suffice.

    RewriteCond $1 !^forum(?:$|/)

    This would go in front of each of the two rewrite rules. Keep in mind that this might not be the best solution, but without being able to troubleshoot, I can't even be certain of the problem.
    Thanks Jeff. Ya I'm pretty sure thats exactly what it's doing - posting to the index. Is that above rule essentially saying exclude /forum? So directly off the root. Not that it is, but if it was ../../forum then it wouldn't work correct? Sorry to bug I just like to somewhat understand things.

    And oh ya here was my other question. If these to rules (old and new) where doing the same thing just written differently then why does the old on work and this new set of rewrites not when it comes to this forum? Is it because the original rewrite only rewrote the root and not all the other folders?

    Code:
    # 301 permanent redirect index.php to folder
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
    RewriteRule ^(([^/]+/)*)index\.php$ http://www.website.com/$1 [R=301,L]
    
    # 301 permanent redirect non-www (non-canonical) to www
    RewriteCond %{HTTP_HOST} !^(www\.website\.com)?$
    RewriteRule (.*) http://www.website.com/$1 [R=301,L]

  4. #4
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    This would go in front of each of the two rewrite rules. Keep in mind that this might not be the best solution, but without being able to troubleshoot, I can't even be certain of the problem.
    If it was indeed writing to the index then this is the "only" solution correct?

  5. #5
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,270
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    Is that above rule essentially saying exclude /forum?
    Yes.

    Quote Originally Posted by PicnicTutorials View Post
    So directly off the root. Not that it is, but if it was ../../forum then it wouldn't work correct? Sorry to bug I just like to somewhat understand things.
    If the web files for forum lived in some other location, then no, none of the rules in this htaccess would be applied. htaccess files are scoped to a filesystem directory. You'd either have to duplicate the htaccess for forum, or you'd have to move your rewrite rules into the server's main configuration file. In the main configuration file, the rewrite rules could be applied in a per-server context rather than per-directory.

    Quote Originally Posted by PicnicTutorials View Post
    And oh ya here was my other question. If these to rules (old and new) where doing the same thing just written differently then why does the old on work and this new set of rewrites not when it comes to this forum? Is it because the original rewrite only rewrote the root and not all the other folders?
    I'm afraid, again, that without being able to see or troubleshoot the issue, I can't know why this is. But if the older rewrites work with your forum while the newer ones don't, then that makes me less confident that my initial guess was correct.
    "First make it work. Then make it better."

  6. #6
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,270
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    If it was indeed writing to the index then this is the "only" solution correct?
    Certainly not the only solution. Another possibility would be to exclude POST requests... which may actually be the better option.
    "First make it work. Then make it better."

  7. #7
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quicky! I believe my forum folder would be ok. Its only the adm/ folder that I was having the issues. adm is directly off the forum... site-root/forum/adm/. Can you please show me how to write that exclusion rule for one more deeper folder? Thanks! I would just guess but I have no idea what all the mumbo jumbo stuff is right after forum.

    original...
    RewriteCond $1 !^forum(?:$|/)

    my guess 1...
    RewriteCond $1 !^forum/adm(?:$|/)

    my guess 2...
    RewriteCond $1 !^adm(?:$|/forum)

  8. #8
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,270
    Mentioned
    18 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    my guess 1...
    RewriteCond $1 !^forum/adm(?:$|/)
    Correct!

    Quote Originally Posted by PicnicTutorials View Post
    ...I have no idea what all the mumbo jumbo stuff is right after forum.

    original...
    RewriteCond $1 !^forum(?:$|/)
    $|/ means end of string ($) or (|) a slash (/). And (?: ) are grouping parentheses. They make sure that the or (|) applies to only what is inside the parentheses. So it will match "forum" followed by either a slash or the end of the string.
    "First make it work. Then make it better."

  9. #9
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Awesome - thanks Jeff!


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
  •