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
-
URL masking
Hi all, Within my organization we maintain a bunch of websites, say child1.com, child2.com and child3.com. It was recently suggested that we merge all three into a single one, say mother.com. The marketing community within my organization strongly argued against this, mainly due to risks related to brand awareness, rank and traffic loss for each of these websites. But we resigned to the idea that we must do it, so we started considering the next proper steps. Now, my understanding is that setting up redirects is crucial in order to cushion the fall and mitigate the losses. However, some people are suggesting url masking. To me personally, url masking doesn't sound like a white hat practice, maybe it's borderline grey, but the bottom line is I need some advice on this topic. Could someone kindly address the following: 1. How is url masking different from url redirect? 2. Is url masking different from url cloaking? 3. Would google penalize us for implementing url masking? 4. Would that have any impact on our PPC campaigns? 5. Are there any documented cases of successful and google-sanctioned websites that are actively using url masking? 6. Are there any pitfalls to using this strategy? Thank you
White Hat / Black Hat SEO | | SimonaCretu0 -
Does ID's in URL is good for SEO? Will SEO Submissions sites allow such urls submissions?
Example url: http://public.beta.travelyaari.com/vrl-travels-13555-online It's our sites beta URL, We are going to implement it for our site. After implementation, it will be live on travelyaari.com like this - "https://www.travelyaari.com/vrl-travels-13555-online". We have added the keywords etc in the URL "VRL Travels". But the problems is, there are multiple VRL travels available, so we made it unique with a unique id in URL - "13555". So that we can exactly get to know which VRL Travels and it is also a solution for url duplication. Also from users / SEO point of view, the url has readable texts/keywords - "vrl travels online". Can some Moz experts suggest me whether it will affect SEO performance in any manner? SEO Submissions sites will accept this URL? Meanwhile, I had tried submitting this URL to Reddit etc. It got accepted.
White Hat / Black Hat SEO | | RobinJA0 -
I have a recipe food blog and use wordpress, but my recipes are usually in more than one category...?
The recipes are in most cases in more than one category (usually two) each. Do and (and if so how) need to set each post to one canicol url? E.g A recipe on Peas is in healthy foods (which is the default wordpress cat.) and also Vegetarian Dishes. I use YOAST for wordpress
White Hat / Black Hat SEO | | Kelly33300 -
Using a geolocation service to serve different banners in homepage. Dangers? Best Practices?
Hello, our website is used by customer in more than 100 countries. Becasuse the countries we serve are so many, we are using one single domain and homepage, without country specific content. Now, we are considering to use an geolocation service to identify the customer location and then to change the contents of one banner in the home page accordingly. Might this be dangerous from a SEO perspective? If yes, any suggesiton on how can we implement this to avoid troubles and penalties form the Search Engines? Thanks in advance for any help,Dario
White Hat / Black Hat SEO | | Darioz0 -
301 domain name URL variants for canonicalization question in htaccess?
#1 RewriteCond %{HTTP_HOST} ^xyz.com [NC] RewriteRule ^(.*)$ http://www.xyz.com/$1 [L,R=301] What I want to do here is to redirect URLs that have omitted the “www.” prefix to the full “www.xyz.com” home page URL. That means the home page URL http://xyz.com will not resolve on its own, but instead will redirect to http://www.xyz.com (without trailing slash). #2 RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index).(html|php|htm)\ HTTP/ [NC] RewriteRule ^(([^/]+/)*)(default|main|index).(html|php|htm)$ http://www.xyz.com/$1 [L,R=301] What I want to do here is to ensure that any home page URL that includes several versions of explicit page name references, such as default.htm or index.html, will be redirected to the canonical home page URL, http://www.xyz.com (without trailing slash). Are the rewrite rules correct? Thanks in advance!
White Hat / Black Hat SEO | | esiow20130 -
I think competitors are trying to remove my links! Have you ever seen this?
Here is the email my sales rep received today (what can we do to combat this?): From: Jaqueline carol [mailto:jaqueline-carol@hotmail.com]
White Hat / Black Hat SEO | | pbhatt
Sent: Wednesday, September 11, 2013 12:57 AM
To:
Subject: I NEED your help - PLEASE Hi, Due to the latest GoogIe update we are working on cleaning up the links to our website . There fore we would like to kindly ask you to remove our link from your page. link details: URL: We believe that it would help both sides to rank up higher in Google and not get penalized during the future Google updates.
Please remove my link at the earliest and notify me about the same. Thank you for your cooperation. Best Regards, Jaquelinecarol1 -
Hidden links in badges using javascript?
I have been looking at a strategy used by a division of Tripadvisor called Flipkey. They specialize in vacation home rentals and have been zooming up in the rankings over the past few months. One of the main off-page tactics that they have been using is providing a badge to property managers to display on their site which links back. The issue I have is that it seem to me that they are hiding a link which has keyword specific anchor text by using javascript. The site I'm looking at offers vacation rentals in Tamarindo (Costa Rica). http://www.mariasabatorentals.com/ Scroll down and you'll see a Reviews badge which shows reviews and a link back to the managers profile on Flipkey. **However, **when you look at the source code for the badge, this is what I see: Find Tamarindo Vacation Rentals on FlipKey Notice that there is a link for "tamarindo vacation rentals" in the code which only appears when JS is turned off in the browser. I am relatively new to SEO so to me this looks like a black hat tactic. But because this is Tripadvisor, I have to think that that I am wrong. Is this tactic allowed by Google since the anchor text is highly relevant to the content? And can they justify this on the basis that they are servicing users with JS turned off? I would love to hear from folks in the Moz community on this. Certainly I don't want to implement a similar strategy only to find out later that Google will view it as cloaking. Sure seems to be driving results for Flipkey! Thanks all. For the record, the Moz community is awesome. (Can't wait to start contributing once I actually know what I'm doing!)
White Hat / Black Hat SEO | | mario330 -
What happens if a company only uses black hat techniques for an extended period of time?
Let's say I were to start a company. Of course, I want to be indexed, crawled, and pulled up in the search engines. So I start using black hat seo techniques. I comment spam, keyword stuff, spin articles, hide text, etc. I publish hundreds of articles per day on well know sites with excellent page rank. If I am doing all of these unethical techniques, what is going to happen to my website?
White Hat / Black Hat SEO | | FrontlineMobility0