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.
User avatar
sohopros
Joomla! Intern
Joomla! Intern
Posts: 63
Joined: Fri Jul 22, 2011 1:51 pm
Contact:

Remove trailing slash from url

Postby 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
Camarillo, CA - USA
Phone 866.644.7646

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

Re: Remove trailing slash from url

Postby 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
Camarillo, CA - USA
Phone 866.644.7646

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

Re: Remove trailing slash from url

Postby 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)
Celebrating 12-Years of Professional Joomla Support Services
- Joomla Professional Support:https://gws-desk.com -
- Joomla Specialized Hosting Solutions:https://gws-host.com -
- Member Joomla Bug Squad & J-CMS Release Team

djadan
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri May 24, 2013 10:03 am

Re: Remove trailing slash from url

Postby 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: 18207
Joined: Mon Aug 29, 2005 10:17 am
Location: Netherlands/ UK/ S'pore/Jakarta/ North America
Contact:

Re: Remove trailing slash from url

Postby leolam » Mon Jul 17, 2017 4:01 pm

Happy for you @djadan to be of help for you

Leo 8)
Celebrating 12-Years of Professional Joomla Support Services
- Joomla Professional Support:https://gws-desk.com -
- Joomla Specialized Hosting Solutions:https://gws-host.com -
- Member Joomla Bug Squad & J-CMS Release Team


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

Who is online

Users browsing this forum: Josh Lewis, sozzled, Webdongle and 8 guests