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.

.htaccess removal of trailing slah causes comment form not to work

March 11, 2009 10:13pm

Subscribe [2]
  • #1 / Mar 11, 2009 10:13pm

    Alejandro Mut

    12 posts

    In order to eliminate duplicates from search engine indexes and to make things neat overall, I’m removing all trailing slashes out of my urls by adding this .htaccess code:

    RewriteCond $1 !^(index\.php)
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

    However, this causes a complete inability to post comments via the comment form.

    Has anyone heard of this one? Any thoughts?

  • #2 / Mar 12, 2009 1:08am

    Brandon Allen

    17 posts

    Try something like this:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
    RewriteRule ^(.*)$ $1/ [L,R=301]

    Just make sure you have this line somewhere before the above code:

    RewriteEngine On
  • #3 / Mar 12, 2009 1:22am

    Alejandro Mut

    12 posts

    Brandon,

    What I’m doing with the code I posted is a 301 redirect from a URL like this:

    http://example.com/articles/my-article-title/

    To this:

    http://example.com/articles/my-article-title

    It is in order to have clean and unique URLs, avoid duplicate content, etc.

    This works perfectly fine. However, for some reason, the comments cannot be posted via the comment form (I have not tried what happens with other EE form tags). Upon submit, the entry page is reloaded as usual, but the comment is not processed at all.

  • #4 / Mar 12, 2009 1:36am

    Brandon Allen

    17 posts

    I’m sorry. I completely read that wrong, and switched “remove” to “add” in my head. Try this code:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^(.+)/$
    RewriteRule ^(.+)/$ /$1 [R=301,L]
  • #5 / Mar 12, 2009 1:55am

    Brandon Allen

    17 posts

    It also might have something to do with the way you’re trying to remove index.php from your URLs.

  • #6 / Mar 12, 2009 1:48pm

    Alejandro Mut

    12 posts

    Brandon,

    Your method does work fine in removing trailing slashes, as did the one I was using. However, It causes the same inability to post comments.

    I am removing my index with the “exclude” method posted on the Wiki section: http://expressionengine.com/wiki/Remove_index.php_From_URLs/#Exclude_List_Method

    I don’t think this has nothing to do, since comments can be posted with the index removed but not when redirecting to remove the trailing slash, with whatever method.

    Ideas anyone?

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

ExpressionEngine News!

#eecms, #events, #releases