Remove trailing slash from url

Discuss Search Engine Optimization in relation to Joomla! 3.x. This forum will also have discussions on SEF/SEO Joomla! 3.x extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
User avatar
sohopros
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Fri Jul 22, 2011 1:51 pm
Contact:

Remove trailing slash from url

Post by sohopros » Fri Jan 06, 2017 10:01 pm

Hi,

I am trying to remove trailing slash from url.
I read several articles and tutorials. Tried applied them on my htaccess file, but no luck
https://joomlaseo.com/checklist/avoid-duplicate-url-s
viewtopic.php?t=701030
http://stackoverflow.com/questions/2141 ... h-from-url


Here will be my .htaccess file.

Code: Select all

##
# @package    Joomla
# @copyright  Copyright (C) 2005 - 2015 Open Source Matters. All rights reserved.
# @license    GNU General Public License version 2 or later; see LICENSE.txt
##

##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE!
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations.  It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that disallows changing it in
# your .htaccess file.  If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's.  If they work,
# it has been set by your server administrator and you do not need it set here.
##

## No directory listings
IndexIgnore *

## Can be commented out if causes errors, see notes above.
Options +FollowSymlinks
Options -Indexes

## Mod_rewrite in use.

RewriteEngine On

## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.

## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects

##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##

# RewriteBase /

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

#This code enabled Gzip for website performance
<ifmodule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
#End Gzip

#This code adds expiration date for file types - mod_deflate
<IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On

    # Default directive
    ExpiresDefault "access plus 1 month"

    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"

    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"

    # CSS
    ExpiresByType text/css "access 1 month"

    # Javascript
    ExpiresByType application/javascript "access plus 1 year"

</IfModule>
#End of mod_deflate

#enables canonical urls redirecting to the www version of the website
RewriteEngine On
RewriteCond %{HTTP_HOST} ^venturaeye33.devsoho.com/
RewriteRule (.*) http://venturaeye33.devsoho.com/$1 [R=301,L]
#end of canonical urls
Please advise,
Sandra
SOHO Prospecting
https://www.sohoprospecting.com - Joomla Website development
Southern California - USA
Phone 866.644.7646

User avatar
sohopros
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 107
Joined: Fri Jul 22, 2011 1:51 pm
Contact:

Re: Remove trailing slash from url

Post by sohopros » Mon Jan 09, 2017 11:52 pm

Hi,

Anyone? Any help would be appreciated.

Sandra
SOHO Prospecting
https://www.sohoprospecting.com - Joomla Website development
Southern California - USA
Phone 866.644.7646

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20652
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: Remove trailing slash from url

Post by leolam » Tue Jan 10, 2017 4:15 am

Load the default .htaccess file provided by Joomla (so we do not get mix-upped) and add this

Code: Select all

RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
to enforce no-trailing-slash. Add this to the section that reads (and uncomment) "## Begin - Custom redirects" When that works I will update the thread with a better version of you .htaccess

Leo 8)
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

User avatar
djadan
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Fri May 24, 2013 10:03 am
Location: London, England
Contact:

Re: Remove trailing slash from url

Post by djadan » Mon Jul 17, 2017 8:48 am

Thanks, @leoalam, that helped me out with the same issue!

User avatar
leolam
Joomla! Master
Joomla! Master
Posts: 20652
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ Germany/ S'pore/Bogor/ North America
Contact:

Re: Remove trailing slash from url

Post by leolam » Mon Jul 17, 2017 4:01 pm

Happy for you @djadan to be of help for you

Leo 8)
Joomla's #1 Professional Services Provider:
#Joomla Professional Support: https://gws-desk.com -
#Joomla Specialized Hosting Solutions: https://gws-host.com -

Sharton
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Nov 01, 2014 5:33 am

Re: Remove trailing slash from url

Post by Sharton » Mon Jun 18, 2018 5:09 pm

What does one do if Joomla refuses to provide or create the .htaccess?
Google won't crawl the site because it says there are trailing slashes and non-trailing slashes and duplicate pages. There are NO duplicate pages - - making it all very confusing as to how to fix something that isn't broken so Lord Goo will crawl the site!

It's a small site with only 12 pages, and a simple menu link to each page.

gws
Joomla! Champion
Joomla! Champion
Posts: 5950
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Remove trailing slash from url

Post by gws » Mon Jun 18, 2018 5:48 pm

Create the .htaccess file with a text editor (notepad++ in windows) and then upload to your site via cpanel or ftp.

annagreenang
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Tue Jun 19, 2018 9:06 pm

Re: Remove trailing slash from url

Post by annagreenang » Tue Jun 19, 2018 9:11 pm

Thanks for the help i my self having the same issue, Thanks again man.

Sharton
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Sat Nov 01, 2014 5:33 am

Re: Remove trailing slash from url

Post by Sharton » Wed Jul 04, 2018 3:24 pm

With this being a Google's "do-it-there-way-or-get-delisted" demand issue since 2014, one would think Jooomla dev would do something at this end.

Just an idea...
s.

tuan91
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Thu Jun 28, 2018 6:33 am

Re: Remove trailing slash from url

Post by tuan91 » Thu Jul 05, 2018 5:00 pm

Thank you @leolam for the solution. I was very unsure whether to remove the trailing slash or not but at the time, i couldnt find a solution until now. I am giving it a try and see how it effect my Website. Thank you again!


Locked

Return to “Search Engine Optimization (Joomla! SEO) in Joomla! 3.x”