Trailing slash 301 redirect code
-
Hi,
I have code for redirecting trailing slash to non-trailing slash, which works fine:
RewriteCond %{HTTP_HOST} !^.yourdomain.co.uk$ [NC]RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
(got code from http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html)
But I cant find a code for redirecting to the trailing slash version anywhere, and I cant modify the above code myself.
Can someone help resolve this issue please, or point me to a resource.
Thanks very much
James
-
Hi Keri,
Thanks for the suggested solution. The enarion solution works for my regular URL's but then causes me issues with some of the more complicated javascript/ajax functionality on the site. No idea why, (bit over my head to be honest) but my developer suggested that it wasnt a good idea to it anyway (again ,for reasons I dont fully understand!)
-
I use Wordpress and Thesis and have them do all the work for me, so I'm not a hands-on expert and can't verify the accuracy of the following URLs, but it looks like they may address your questions. Let us know if one of these works for you.
http://enarion.net/web/htaccess/trailing-slash/
http://soulpass.com/2008/01/11/htaccess-add-trailing-slash-to-url/ (be sure to read whole post)
-
no, google can (and often does) index both pages as separate URL's
-
Hi Rene,
Sorry for the delay in getting back to you. It's this one "/".
I'm not in favour of using the canonical tag as it's not a directive, so I want ideally a 301 redirect code for it
thanks
-
the reson is: Back in the day (I do not know if it still does this, havent tested it or had cause to do so.) google indexed example.com/page/ and example.com/page as two different pages.
The quick fix is to make a RegEx that "tests for the excistense of a trailing slash at the end ofg the url" and then use that in your .htaccess to redirect all urls without to an url with. In other words add a trailing slash. (makes sence I hope.)
You could do the same thing with rel=canonical (even easier imo. since you can use php and do it in the relevant templates)
Here is Matts word on trailing slashes: http://www.mattcutts.com/blog/seo-advice-url-canonicalization/#comment-8260
-
Then why it is suggested to have one version - with or without trailing slash ?
-
In my experience no
-
If a URL has trailing slash ( / ), and a user types the URL without trailing slash, would an 404 error will be shown ?
-
I could probably be of service but since I'm Danish You'll have to give me an example of a "trailing" slash.. A guess it's a slash that tips the left? eg: "" or is it this one: "/"
if you help me understand what you mean I might be able to help you
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Meta descriptions and h1 tags during a 301 redirect
My employer is shifting to a new domain and i am in the midst of doing URL mapping. I realize that many of the meta descriptions and H1 tags are different on the new pages - is this a problem ? Thank you.
Technical SEO | | ptapley0 -
301 redirect not working
Hi there! I have recently moved a domain that has been indexed by google and setup redirects so that it forwards to the new domain. It seems like the only redirect that actually is working is the canonical and main domain but every other page and or page nested within a folder are not working. Here is an example of some of the redirects. Am I doing this wrong? It seems to be going to the new domain but can't find the actual pages.... RewriteEngine On
Technical SEO | | twotd
RewriteBase /
RewriteCond %{HTTP_HOST} !agoodsweep.com$ [NC]
RewriteRule ^(.*)$ http://agoodsweep.com/$1 [L,R=301]
redirect 301 woodstoveservicerepair.html http://agoodsweep.com/woodstoveservicerepair/
redirect 301 /westchesterchimney.html http://agoodsweep.com/west-chester-chimney/ Thanks in advance for any help!!0 -
How to verify a page-by-page level 301 redirect was done correctly?
Hello, I told some tech guys to do a page-by-page relevant 301 redirect (as talked about in Matt Cutts video https://www.youtube.com/watch?v=r1lVPrYoBkA) when a company wanted to move to a new domain when their site was getting redesigned. I found out they did a 302 redirect on accident and had to fix that, so now I don't trust they did the page-by-page relevant redirect. I have a feeling they just redirected all of the pages on the old domain to the homepage of the new domain. How could I confirm this suspicion? I run the old domain through screaming frog and it only shows 1 URL - the homepage. Does that mean they took all of the pages on the old domain offline? Thanks!
Technical SEO | | EvolveCreative0 -
301 redirecting old content from one site to updated content on a different site
I have a client with two websites. Here are some details, sorry I can't be more specific! Their older site -- specific to one product -- has a very high DA and about 75K visits per month, 80% of which comes from search engines. Their newer site -- focused generally on the brand -- is their top priority. The content here is much better. The vast majority of visits are from referrals (mainly social channels and an email newsletter) and direct traffic. Search traffic is relatively low though. I really want to boost search traffic to site #2. And I'd like to piggy back off some of the search traffic from site #1. Here's my question: If a particular article on site #1 (that ranks very well) needs to be updated, what's the risk/reward of updating the content on site #2 instead and 301 redirecting the original post to the newer post on site #2? Part 2: There are dozens of posts on site #1 that can be improved and updated. Is there an extra risk (or diminishing returns) associated with doing this across many posts? Hope this makes sense. Thanks for your help!
Technical SEO | | djreich0 -
Delete 301 redirected pages from server after redirect is in place?
Should I remove the redirected old pages from my site after the redirects are in place? Google is hating the redirects and we have tanked. I did over 50 redirects this week, consolidating content and making one great page our of 3-10 pages with very little content per page. But the old pages are still visible to google's bot. Also, I have not put a rel canonical to itself on the new pages. Is that necessary? Thanks! Jean
Technical SEO | | JeanYates0 -
Where does Wordpress store the 301 redirects?
Hi, I've just created a campaign for my new wordpress blog and found 11 301 redirects which I was not aware of. It looks like wordpress has created them automatically. Does any one know how wordpress handles this issues or where are they stored so I can delete them? They are of no use for me. 9 of these redirects point to the same url with an added '/' and are in pages 1 is on a post. I've been changing the permalink and some urls several times and maybe one of these times the Wordpress has automatically created the 301 redirect. But why? I do not want to keep the old url. the last redirect is very strange it goes from http://www.mydomain.com/folder to http://www.mydomain.com where folder is the folder where I installed wordpress. But again, I want no one to type the url with the folder name or even know this folder exists. Any comment on this would be greatly appreciated. Thanks a lot, David
Technical SEO | | dballari0 -
Loss of search engine positions after 301 redirect - what went wrong?!?
Hi Guys After adhering to the On Page optimisation suggestions given by SEOmoz, we redirected some of old urls to new ones. We set 301 redirects from the old pages to new on a page by page basis but our search engine ranking subsequently fell off the radar and lost PR. We confirmed redirection with fiddler and it shows 301 permanent redirect on every page as expected. To manage redirection using a common code logic we executed following: In Http module, using “rewrite path” we route “all old page requests” to a page called “redirect.aspx? oldpagename =[oldpagename]”. This happens at server side. In redirect.aspx we are redirecting from old page to new page using 301 permanent redirect. In the browser, when old page is requested, it will 301 redirect to new page. In hope we and others can learn from our mistakes - what did we do wrong ?!? Thanks in advance. Dave - www.paysubsonline.com
Technical SEO | | Evo0 -
Joomla 301 redirects
hi i am using joomla sef404 and i have 7000 not found pages in my webmaster google tool page. the trouble is i got rid of a lot of pages and also components so now i am left with loads of not found pages. what i want to try and do is to create 301 redirects so that i do not lose page rank. can anyone please let me know how to do this step by step please
Technical SEO | | ClaireH-1848860