#1
  1. SEO Guy
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    147
    Rep Power
    87

    Question .htaccess rules for non-trailing slash "/"


    Hello All,

    Visiting the forum for help after some long time.

    First of all, I am a novice in writing .htaccess rules.
    Yesterday, one of my developer was working on some changes and he mistakenly wrote something wrong without taking the backup, which I can't identify now.

    The website I am talking about is currently up with default WordPress redirect rules, showing a trailing / in the URLs.
    Previously the URLs were not followed by the /. This will create redundancy in analytics data.

    I need your help to make changes to below .htaccess code making the URLs redirect from / to non-/

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    Thanks in advance
  2. #2
  3. Just a Photographer
    SEO Chat Adventurer (500 - 999 posts)

    Join Date
    May 2011
    Location
    Atwater, CA
    Posts
    752
    Rep Power
    1384
    Not a .htaccess guru either but I did a search and found this: php - Htaccess: add/remove trailing slash from URL - Stack Overflow

    Comments on this post

    • Shobhit Saxena agrees
    - Mike

    Jack of all trades, master of none.
  4. #3
  5. SEO Guy
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    147
    Rep Power
    87
    Thanks MiKe for the quick response, but looks the rewrite rules from the thread isn't working for me. :-)

    RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L,R=301]

    Tried it in following formats:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    </IfModule>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    RewriteRule . /index.php [L]
    </IfModule>

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>


    Still looking for help.
  6. #4
  7. Super Moderator
    SEO Chat Good Citizen (1000 - 1499 posts)

    Join Date
    May 2015
    Location
    United Kingdom
    Posts
    1,339
    Rep Power
    2161
    This may be able to help you out: https://moz.com/community/q/how-to-f...ailing-slashes

    Comments on this post

    • Shobhit Saxena agrees
    Always happy to help in private message. | Learn about my latest project Can You Get Automated Pages To Rank In Google?
    Useful Links: Useful SEO Tools | GTmetrix | FileOptimizer | Cloudflare
  8. #5
  9. Contributing User
    SEO Chat Adventurer (500 - 999 posts)

    Join Date
    Apr 2011
    Posts
    939
    Rep Power
    1330
    Try StackOverflow for this sort of thing. That's where I go.

    Comments on this post

    • Shobhit Saxena agrees
  10. #6
  11. SEO Guy
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    147
    Rep Power
    87
    Thanks Thomas for the article.
    Doodled, yap Stack Overflow helps a lot in such scenarios, but sometimes it is lot confusing.

    Posted this thread here just to see if some of our experts here have handled the scenario, will definitely post the .htaccess rule here for same once the issue is sorted. :-)
  12. #7
  13. No Profile Picture
    Contributing User
    SEO Chat Adventurer (500 - 999 posts)

    Join Date
    Sep 2016
    Posts
    775
    Rep Power
    1917
    The problem is your order I believe.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]


    RewriteRule (.+)/$ $1 [R=301,L]


    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
  14. #8
  15. SEO Guy
    SEO Chat Discoverer (100 - 499 posts)

    Join Date
    Mar 2013
    Location
    India
    Posts
    147
    Rep Power
    87
    Fortunately got an instance of the old .htaccess file on backup repo. and that one worked.
    Here is the script:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_URI} !^/wp-admin
    RewriteRule (.+)/$ $1 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    RewriteCond %{http_host} ^domain.com [nc]
    RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

    RewriteCond %{REQUEST_URI} !(/$|\.)
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]

    </IfModule>

    This one looks more complex than the above one we we discussing :-)
    Hey! I am Shobhit, working as Asst. Manager Online Marketing in New Delhi, India.
    I am an avid and omnivorous reader as far as SEO and smartphones are concerned. I also have a blog on Search Engine Optimization that shares a few tips and tricks on SEO.

Similar Threads

  1. Why is a "trailing text" appaearing in all titles of my pages in SERPS?
    By Dinrock in forum Search Engine Optimization
    Replies: 3
    Last Post: Jun 2nd, 2016, 07:11 AM
  2. EU to slash mobile phone "roaming" charges (Reuters)
    By RSS_News_User in forum Technology News
    Replies: 0
    Last Post: Jul 12th, 2006, 10:07 AM
  3. EU plans to slash mobile phone "roaming" charges (Reuters)
    By RSS_News_User in forum Technology News
    Replies: 0
    Last Post: Jul 12th, 2006, 07:06 AM
  4. Replies: 6
    Last Post: Nov 18th, 2004, 06:32 AM
  5. Trailing "/" on URL causing no PR?
    By curvity in forum Google Optimization
    Replies: 1
    Last Post: Jul 23rd, 2003, 01:23 PM

IMN logo majestic logo threadwatch logo seochat tools logo