How to remove trailing slashes in URLs using .htaccess (Apache)?
-
I want my URLs to look like these:
http://www.domain.com/buy/shoes
http://www.domain.com/buy/shoes/red
Thanks in advance!
-
I am sorry my friend. Somehow I missed your response.
It should have been: RewriteRule ^(.*)/$ /$1 [R,L]
So, you missed the /
And it is also used to remove the trailing slash from URLs just like the one that I gave you earlier.
Best,
Devanur Rafi
-
And what is the difference of this to the one you've answered?
RewriteBase /
RewriteRule ^(.*)/$ $1 [R,L] -
Thanks Devanur! Big help. By the way, I'm still looking for an opinion about this and I'm sure you can help me with this issue:http://moz.com/community/q/how-can-i-301-redirect-a-series-of-pages-ex-page-1-page-2-page-3-to-one-landing-page-new-url
-
Hi, here you go.....
RewriteRule ^(.)/(?.)?$ $1$2 [R=301,L]
Please note that the thing which looks like a capital V in the above rule is actually the backward slash and forward slash together.
Best,
Devanur Rafi
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
-
Canonical tag On Each Page With Same Page URL - Its Harmful For SEO or Not?
Hi. I have an e-commerce project and they have canonical code in each and every page for it's own URL. (Canonical on Original Page No duplicate page) The url of my wesite is like this: "https://www.website.com/products/produt1"
White Hat / Black Hat SEO | | HuptechWebseo
and the site is having canonical code like this: " This is occurring in each and every products as well as every pages of my website. Now, my question is that "is it harmful for the SEO?" Or "should I remove this tags from all pages?" Is that any benefit for using the canonical tag for the same URL (Original URL)?0 -
How Important is it to Use Keywords in the URL
I wanted to know how important this measure is on rankings. For example if I have pages named "chair.html" or "sofa.html" and I wanted to rank for the term seagrass chair or rattan sofa.. Should I start creating new pages with the targeted keywords "seagrass-chair.html" and just copy everything from the old page to the new and setup the 301 redirects?? Will this hurt my SEO rankings in the short term? I have over 40 pages I would have to rename and redirect if doing so would really help in the long run. Appreciate your input.
White Hat / Black Hat SEO | | wickerparadise0 -
Vanity URLs Canonicalization
Hi, So right now my vanity URLs have a lot more links than my regular homepage. They 301 redirect to the homepage but I'm thinking of canonicalizing the homepage, as well as the mobile page, to the vanity URL. Currently some of my sites have a vanity URL in a SERP and some do not. This is my way of nudging google to list them all as vanity but thought I would get everyone's opinion first. Thanks!
White Hat / Black Hat SEO | | mattdinbrooklyn1 -
Partial Manual penalty to a URL
Hi Mozers, I have a website which has got a partial manual penalty on a specific url. That url is of no use to the website now and is going to be taken off in 3 months time as the website is going to be completely redesigned. Till then I dont wont to live with the partial manual penalty for this url. I have few things in mind to tackle this: 1. take out the url from the website now (as the new redesign will take 3 months) 2. take out internal links pointing to this url in question 3. file for reconsideration with google stating we have taken off the url and have not generated any backlinks and the backlinks are organic. (no backlinking activity has been done on this website or the url) Please let me know if this works or i will have to get the backlinks removed then the disavow then the reconsideration. Looking forward for ur response 🙂
White Hat / Black Hat SEO | | HiteshBharucha0 -
I've purchased a PR 6 domain what will be best use of it ?
I've purchased a PR 6 domain what will be best use of it ? Should make a new site or redirect it to my low pr sites? Or I wasted my $100 ?
White Hat / Black Hat SEO | | IndiaFPS0 -
How should I use the 2nd link if a site allows 2 in the body of a guest post?
I've been doing some guest posting, and some sites allow one link, others allow more. I'm worried I might be getting too many guest posts with multiple links. I'd appreciate your thoughts on the following: 1. If there are 50+ guest posts going to my website (posted over the span of several months), each with 2 links pointing back only to my site is that too much of a pattern? How would you use the 2nd link in a guest post if not to link to your own site? 2. Does linking to .edu or .gov in the guest post make the post more valuable in terms of SEO? Some people recommend using the 2nd link to do this. Thanks!
White Hat / Black Hat SEO | | pbhatt0 -
URL structure: 301 redirect or leave as is?
Hello, My website, www.coloringbookfun.com is very old and authoritative, but the URL structure is terrible. If you check out some of our subcategories such as http://www.coloringbookfun.com/Kung Fu Panda and individual printables such as http://www.coloringbookfun.com/Kung Fu Panda/imagepages/image2.html You can see that they aren't optimized. I am curious to know the pros and cons of fixing the URL structure and 301ing them to the new optimized url. Will 301ing lose authority and backlinks for the sites pages? Does optimizing the url structure outweigh losing the authority/backlinks?
White Hat / Black Hat SEO | | WebServiceConsulting.com0 -
Using Yext - Opinions? Thoughts? Harmful effects on SEO?
Hi All, Does anyone have any experience using Yext? We have 36 locations across the US and I think it would be great to get our local listings knocked out efficiently. Can anyone provide information on the directories they list you in (perhaps Google places listings, for example)? Also, can anyone provide feedback as to whether or not there is any harm with blasting so many directories at once? I don't want to do anything that might harm our SEO rankings or provide low quality links. Thanks in advance!
White Hat / Black Hat SEO | | CSawatzky0