Removing Trailing Slashes from URLs
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.
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.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun Aug 28, 2011 9:20 pm
Removing Trailing Slashes from URLs
Hi guys,
I've been working on optimizing the my website built with Joomla. I need to remove trailing slashes from my urls since the search engines have been indexing them as two separate ones.
example:
www.mywebsite.com/link/
www.mywebsite.com/link
Right now i have a code on .htaccess which redirects the non-www version of my website to www version. I need to either remove or add slashes to all my urls to make sure they stay consistence.
Could anybody help me with this?
Thanks
I've been working on optimizing the my website built with Joomla. I need to remove trailing slashes from my urls since the search engines have been indexing them as two separate ones.
example:
www.mywebsite.com/link/
www.mywebsite.com/link
Right now i have a code on .htaccess which redirects the non-www version of my website to www version. I need to either remove or add slashes to all my urls to make sure they stay consistence.
Could anybody help me with this?
Thanks
-
- Joomla! Enthusiast
- Posts: 107
- Joined: Wed Jul 20, 2011 7:02 pm
Re: Removing Trailing Slashes from URLs
using apache mod_rewrite in your .htaccess file...
RewriteBase /
RewriteRule ^(.*)/$ $1 [R,L]
RewriteBase /
RewriteRule ^(.*)/$ $1 [R,L]
-
- Joomla! Intern
- Posts: 64
- Joined: Sun Aug 28, 2011 9:20 pm
Re: Removing Trailing Slashes from URLs
Thanks for your reply. I'm glad you brought this subject up so I can update this thread. Actually i solve the issue using the code belowlowrykun wrote:using apache mod_rewrite in your .htaccess file...
RewriteBase /
RewriteRule ^(.*)/$ $1 [R,L]
RewriteCond %{HTTP_HOST} ^(www.)?mywebsite\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
the problem was I was inserting the code in the wrong spot on .htaccess file. I put the code between the area for custom redirects and it worked well.
-
- Joomla! Enthusiast
- Posts: 107
- Joined: Wed Jul 20, 2011 7:02 pm
Re: Removing Trailing Slashes from URLs
Side note...
I checked my Google Webmaster Tools and I didn't have any trailing slashes indexed:
I had :
/en/blog
/en/product
but duplicates with the trailing slash didn't exist.
You can look on the 'internal links' and search for ones with the trailing slash. You can also search google for both versions of the links. I didn't see that they were both being indexed.
I checked my Google Webmaster Tools and I didn't have any trailing slashes indexed:
I had :
/en/blog
/en/product
but duplicates with the trailing slash didn't exist.
You can look on the 'internal links' and search for ones with the trailing slash. You can also search google for both versions of the links. I didn't see that they were both being indexed.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun Aug 28, 2011 9:20 pm
Re: Removing Trailing Slashes from URLs
That's a good point. I think Google now handle the slashes pretty well and that means there is a little chance that both URLs (w/ and w/o slashes) get indexed. However, my main reason to remove the slashes islowrykun wrote:Side note...
I checked my Google Webmaster Tools and I didn't have any trailing slashes indexed:
I had :
/en/blog
/en/product
but duplicates with the trailing slash didn't exist.
You can look on the 'internal links' and search for ones with the trailing slash. You can also search google for both versions of the links. I didn't see that they were both being indexed.
1) to be safe from duplicate indexing
2) to have canonical url reporting on Google Analytic and other analysis software.
On Google analytic i've seen many cases which google shows two separate data for the URL with slash and without the slash. Overall i don't think it hurts SEO as it used to before.
-
- Joomla! Enthusiast
- Posts: 107
- Joined: Wed Jul 20, 2011 7:02 pm
Re: Removing Trailing Slashes from URLs
I noticed that this worked on the front end fine, but caused an infinite loop on the backend. It seems that on the back end it redirects:
administrator -> administrator/
Then we removed the trailing slash and redirected again.
So you'd need to make changes to exclude this - however, since we've noticed that it doesn't appear to affect Google, then I'm in favor of leaving it alone.
administrator -> administrator/
Then we removed the trailing slash and redirected again.
So you'd need to make changes to exclude this - however, since we've noticed that it doesn't appear to affect Google, then I'm in favor of leaving it alone.
-
- Joomla! Intern
- Posts: 64
- Joined: Sun Aug 28, 2011 9:20 pm
Re: Removing Trailing Slashes from URLs
yes i had the same issue! i just insert a separate htaccess file on Administrator folder and it solved the issue (i don't know if it was a good idea or not but it worked!). again my main issue was working on anlaysis and it was really annoying to get data for two separate url which you know it's the same thing.lowrykun wrote:I noticed that this worked on the front end fine, but caused an infinite loop on the backend. It seems that on the back end it redirects:
administrator -> administrator/
Then we removed the trailing slash and redirected again.
So you'd need to make changes to exclude this - however, since we've noticed that it doesn't appear to affect Google, then I'm in favor of leaving it alone.
-
- Joomla! Intern
- Posts: 52
- Joined: Fri Mar 25, 2011 7:06 pm
- Contact:
Re: Removing Trailing Slashes from URLs
Some search engines remove the trailing slash from urls that look like directories - e.g. Yahoo does it. However it could result into duplicated content problems when the same page content is accessible under different urls. The solution is to create a .htaccess rewrite rule that adds the trailing slashes to these urls. Example - redirect all urls that do not have a trailing slash to urls with a trailing slash:
Note: RewriteCond %{REQUEST_URI} !example.php
excludes a sample url that should not be rewritten. This is just an example. If you do not have a file or url that should not be rewritten, remove this line.
Code: Select all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !example.php
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
excludes a sample url that should not be rewritten. This is just an example. If you do not have a file or url that should not be rewritten, remove this line.
- nhartsog
- Joomla! Apprentice
- Posts: 13
- Joined: Wed Mar 20, 2013 8:04 pm
- Location: St. Louis, MO
- Contact:
Re: Removing Trailing Slashes from URLs
This may be a dead forum thread, but just in case it helps anyone else who happens to search for this problem. My .htaccess file was removing the trailing slashes, which worked for every address except the infinite loop redirect for /administrator that lowrykun mentioned. I fixed this by entering directly above the already present RewriteRule to remove trailing slashes and it works perfectly. I end up with the following:
Hope this helps someone; it was bothering me for days!
Code: Select all
RewriteCond %{REQUEST_URI} !administrator
Code: Select all
RewriteBase /
#
# Remove Trailing Slash (Normally would be the opposite)
# Excluding the administrator folder to prevent infinite redirect issue.
RewriteCond %{REQUEST_URI} !administrator
RewriteRule ^(.*)/$ $1 [R=301,L]
-
- Joomla! Fledgling
- Posts: 2
- Joined: Mon Mar 25, 2013 1:51 pm
- Contact:
Re: Removing Trailing Slashes from URLs
Hi thanks for the code, one question when you put a trailing slash on it reverts you back to the home page, is there not a way for it to stay on the same page only removing the trailing slash.
- trogladyte
- Joomla! Guru
- Posts: 583
- Joined: Sat May 03, 2008 9:27 pm
- Location: Phoenix, AZ
- Contact:
Re: Removing Trailing Slashes from URLs
Thank you so much to all involved here! The trailing slashes were driving me nuts. On the first site I just did separate redirects for them all (just 5 pages) so that was easy. Next site had 100's of pages..... Not happy till I discovered this thread.
My question is why does Joomla even do this out of the box? Seems extremely stupid to automatically duplicate the pages... IMH (and somewhat unskilled) O!
My question is why does Joomla even do this out of the box? Seems extremely stupid to automatically duplicate the pages... IMH (and somewhat unskilled) O!
Ian Shere - Phoenix Website Design & Hosting
http://www.citruskiwi.com
Certified Flight Instructor http://www.flygoodyear.com
http://www.citruskiwi.com
Certified Flight Instructor http://www.flygoodyear.com
-
- Joomla! Apprentice
- Posts: 8
- Joined: Wed Oct 10, 2012 12:52 pm
Re: Removing Trailing Slashes from URLs
I found this produces a redirect loop when accessing directories, eg: /images/nhartsog wrote:This may be a dead forum thread, but just in case it helps anyone else who happens to search for this problem. My .htaccess file was removing the trailing slashes, which worked for every address except the infinite loop redirect for /administrator that lowrykun mentioned. I fixed this by enteringdirectly above the already present RewriteRule to remove trailing slashes and it works perfectly. I end up with the following:Code: Select all
RewriteCond %{REQUEST_URI} !administrator
Hope this helps someone; it was bothering me for days!Code: Select all
RewriteBase / # # Remove Trailing Slash (Normally would be the opposite) # Excluding the administrator folder to prevent infinite redirect issue. RewriteCond %{REQUEST_URI} !administrator RewriteRule ^(.*)/$ $1 [R=301,L]
The solution is to add this line:
Code: Select all
RewriteCond %{REQUEST_FILENAME} !-d
Code: Select all
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !administrator
RewriteCond %{REQUEST_URI} !component
RewriteRule ^(.*)/$ $1 [R=301,L]
EDIT: I had to add this line: to prevent invalid token on frontend login:
Code: Select all
RewriteCond %{REQUEST_URI} !component
-
- Joomla! Fledgling
- Posts: 3
- Joined: Tue Nov 18, 2014 6:52 pm
- Location: UK
- Contact:
Re: Removing Trailing Slashes from URLs
Genius teokolo Thanksteokolo wrote:I found this produces a redirect loop when accessing directories, eg: /images/nhartsog wrote:This may be a dead forum thread, but just in case it helps anyone else who happens to search for this problem. My .htaccess file was removing the trailing slashes, which worked for every address except the infinite loop redirect for /administrator that lowrykun mentioned. I fixed this by enteringdirectly above the already present RewriteRule to remove trailing slashes and it works perfectly. I end up with the following:Code: Select all
RewriteCond %{REQUEST_URI} !administrator
Hope this helps someone; it was bothering me for days!Code: Select all
RewriteBase / # # Remove Trailing Slash (Normally would be the opposite) # Excluding the administrator folder to prevent infinite redirect issue. RewriteCond %{REQUEST_URI} !administrator RewriteRule ^(.*)/$ $1 [R=301,L]
The solution is to add this line:So this is the complete code I use inside "Custom redirects" section of my .htaccess:Code: Select all
RewriteCond %{REQUEST_FILENAME} !-d
Hope it helps someone!Code: Select all
RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !administrator RewriteCond %{REQUEST_URI} !component RewriteRule ^(.*)/$ $1 [R=301,L]
EDIT: I had to add this line: to prevent invalid token on frontend login:Code: Select all
RewriteCond %{REQUEST_URI} !component