ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Comments won’t submit (.htaccess trailing slashes)

August 01, 2011 9:05am

Subscribe [4]
  • #1 / Aug 01, 2011 9:05am

    Jon @ Kernel

    122 posts

    This question may be related to a resolved thread.

    Hello - I’m having this same issue with comments, which seem to have stopped submitting when I updated to 2.2. - it’s related to us forcing a trailing slash on URLs, which is crucial for our SEO (when I remove the offending 3 lines, the comment submission works, but we’re obviously losing our trailing slashes).

    There’s a specific reference to CI here: https://github.com/paulirish/html5-boilerplate/wiki/proper-usage-of-trailing-slash-redirects

    This code works sitewide, but doesn’t seem to like our comments (the comments don’t get submitted):

    RewriteBase /
    
    # Add www at start of URLs
    RewriteCond %{HTTP_HOST} ^mysite\.com$ [NC]
    RewriteRule ^(.*) <a href="http://www.mysite.com/$1">http://www.mysite.com/$1</a> [L,R=301]
    
    # Force trailing slash on URLs
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
    RewriteRule ^(.*)$ $1/ [R=301,L]
    
    # Remove index.php from job board
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^jobs/(.*)$ jobs/index.php/$1 [L]
    
    # this gets rid of index.php elsewhere
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1

    Do you have any suggestions for the correct htaccess setup for this one?  As I said, it’s really important that we have this working again.

    Thanks!

  • #2 / Aug 02, 2011 1:50am

    John Henry Donovan

    12339 posts

    Hi Jon,

    What version and build of EE are you using?
    Are you using any add-ons?

    Is this htaccess in your root of the a directory for your jobs MSM site?

    What exactly happens when you submit a comment?
    Is there an error, a blank page?

    Have you got a link to where we can see it happening?

    using Firebug or similar can you see where any URLs erroring?

    Can you share the Comment Entry tags?

  • #3 / Aug 02, 2011 9:19pm

    Jon @ Kernel

    122 posts

    Hey John

    It’s the latest 2.2.2 build.

    This htaccess is in the root of the site - /jobs/ is in a subdirectory, but doesn’t have a separate .htaccess.

    The comment form loads up, but upon submission of a comment, it just reloads the page (just like it does when a comment is successfully submitted and the user is redirected back to the original page, but there’s no comment added).

    You can check out one (of plenty) example pages here: http://www.cafedelabourse.com/archive/article/sentiment-de-marche-cette-semaine-fortement-negatif/

    The three ‘test’ comments on that page are ones I successfully posted when I modified the htaccess to temporarily remove the trailing slash rule.

    I’m almost 100% certain it isn’t the comments form code itself, as it works perfectly when I remove the trailing slash .htaccess rule, but here’s a simplified version of the code anyway!

    {exp:channel:entries limit="1" require_entry="yes" status="not pending|closed"}
    {exp:comment:form}
        
    <fieldset class="contact-form">
        <div id="authorinfo">
            {if logged_in}
            <input type="hidden" name="name" id="name" value="{logged_in_screen_name}" class="comment_name_input" tabindex="2" />
            <input type="hidden" name="email" id="email" value="{logged_in_email}" class="comment_email_input" tabindex="3" />
            <span class="hint">Votre email est requis.</span>
            {if:else}
            <label for="name">Nom</label>
            <input type="text" name="name" id="name" value="" class="comment_name_input" tabindex="2" />
            <label for="email">Email</label>
            <input type="text" name="email" id="email" value="" class="comment_email_input" tabindex="3" />
            {/if}
        </div>
    
        <textarea name="comment" rows="25" cols="30" tabindex="1" id="comment-text">{comment}</textarea>
        <div class="submission">
            <input type="checkbox" name="notify_me" id="notify" value="yes" {notify_me} /> <label for="notify">Me prévenir par email de nouveaux commentaires ?</label>
            <input type="submit" name="submit" id="submit" value="Soumettre" class="button" />
        </div>
    </fieldset>
    
    {/exp:comment:form}
    {/exp:channel:entries}
  • #4 / Aug 03, 2011 10:45pm

    Lisa Wess

    20502 posts

    Hi, Jon -

    What is likely happening is the form is mismatching something like

    example.com

    vs

    example.com/

    Unfortunately forcing trailing slashes via mod_rewrite is beyond what we can offer support for, so I’m going to shift this down to Community Help; hopefully someone has overcome this particular issue and can help out.

    Thank you.

  • #5 / Aug 04, 2011 12:37am

    the3mus1can

    426 posts

    The .htaccess rule is causing the redirect from the none trailing slash url to the url with a trailing slash. This redirect is causing the $_POST data to get lost from the original form submission.  Below is a less than elegant solution, but should work:

    $(function() {
        var form = $('#comment_form');
        form.attr('action', form.attr('action')+'/');
    });

    We are just using a little JS to add the trailing slash to the end of the comment forms action url.

  • #6 / Aug 04, 2011 12:27pm

    Jon @ Kernel

    122 posts

    Ah, thanks the3mus1can - I wish I’d picked that up earlier as I’d have given it a shot.  I figured this was the case too - I’ll give your little JS fix a shot on the next site we need to do this for! 

    In the meantime, we’ve ended up just switching to stripped out trailing slashes, which seems to work fine so far.  Cheers anyway!

  • #7 / Oct 07, 2011 7:34am

    sm9

    352 posts

    The .htaccess rule is causing the redirect from the none trailing slash url to the url with a trailing slash. This redirect is causing the $_POST data to get lost from the original form submission.  Below is a less than elegant solution, but should work:

    $(function() {
        var form = $('#comment_form');
        form.attr('action', form.attr('action')+'/');
    });

    We are just using a little JS to add the trailing slash to the end of the comment forms action url.

    I’ve just came across this exact same issue, and your JavaScript workaround worked a treat, so thanks for sharing this. 😊

    I’ll tell you what though - it’s a bit annoying how EE2 handles trailing forward slashes. I’d like complete control over these to avoid issues like this, as there’s a hell of a lot of sites out there that don’t remove the trailing slash. Also came across similar issues when using CartThrob.

    Thanks,

    Stephen

  • #8 / Feb 07, 2012 10:25am

    FortySeven Media

    130 posts

    Yeah forcing the trailing slash is very standard practice…most of my clients have SEO companies and they want this done. We shouldn’t have to be worried that random pieces of the site will break..especially something like this where there’s no sign of any errors other than the comment not showing up.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases