Redirect url that don't end with slash
-
Hi!
I need to add in my .htaccess a way to redirect URL that don't end with / to the one thats end wth /.For example, I need http://example.com to redirect to http://www.example.com/. And, of course, this redirection should be only for URLs that don't end with /, so I don't get double // at the end.
I already have the code to redirect the non-www to the www, but can't find a way to do the slash thing.
Thanks!
-
Thank you both!
-
do you have a number of URLS that you need to redirect ? or do you just want to redirect http://example.com to http://www.example.com/
This will add trailing slash to any URL
Add a trailing slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301] -
Hi Ariel,
I have found something on Stackoverflow: http://stackoverflow.com/questions/7780859/htaccess-rewrite-to-force-trailing-slash-at-the-end
Maybe you want to check it out, if it works for you.
Gr., Keszi
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
-
Clean URL vs. Parameter URL and Using Canonical URL...That's a Mouthfull!
Hi Everyone, I a currently migrating a Magento site over to Shopify Plus and have a question about best practices for using the canonical URL. There is a competitor that I believe is not doing it the correct way, so I want to make sure my way is the better choice. With 'Vendor Pages' in Shopify, they show up looking like: https://www.campusprotein.com/collections/vendors?q=Cellucor. Not as clean. Problem is that Shopify also creates https://www.campusprotein.com/collections/cellucor. Same products, same page, just a different more clean URL. I am seeing both indexed in Google. What I want to do is basically create a canonical URL from the URL with the parameter that points to the clean URL. The two pages are very similar. The only difference is that the clean URL page has some additional content at the top of the page. I would say the two pages are 90% the same. Do you see any issue with that?
Technical SEO | | vetofunk0 -
How do I ensure that colour variant products aren't flagged for being duplicate?
I have a site with 12 colour variants of 1 style. How do I ensure that these are not flagged as duplicate content as they currently have been?
Technical SEO | | Ashcastle0 -
Are image pages considered 'thin' content pages?
I am currently doing a site audit. The total number of pages on the website are around 400... 187 of them are image pages and coming up as 'zero' word count in Screaming Frog report. I needed to know if they will be considered 'thin' content by search engines? Should I include them as an issue? An answer would be most appreciated.
Technical SEO | | MTalhaImtiaz0 -
Can new content be added to a url which has a 301 redirect?
I am working on a site which is currently being redesigned. The home page currently ranks highly for relevant search terms, although on the new site the content on this page will be removed. The solution I was considering, to preserve rankings, was to move the content on the home page to a new url, and use a 301 redirect to help preserve rankings for that particular page. The question I have therefore, is am I able to add new content to the home page, and have this page freshly indexed accordingly? Any thoughts or suggestions would be most welcome. Thanks, Matt.
Technical SEO | | MatthewA0 -
I've consolidated other domains to a single one with 301 redirects, yet the new domain authority in MOZ is much less that the redirected ones. Is that right?
I'm trying to increase the domain authority of my main site, so decided to consolidate other sites. One of the other sites has a much higher domain authority, but I don't know why after a 301 redirect, the new site's domain authority hasn't changed on over a month. Does MOZ take account of thes types of things?
Technical SEO | | bytecgroup2 -
Unused url 'A' contains frameset - can it damage the other site B?
Client has an old unused site 'A' which I've discovered during my backlink research. It contains this source code below which frames the client's 'proper' site B inside the old unused url A in the browser address. Quick question - will google penalise the website B which is the one I'm optimising? Should the client be using a redirect instead? <frameset <span class="webkit-html-attribute-name">border='0' frameborder='0' framespacing='0'></frameset <span> <frame src="http: www.clientwebsite.co.ukb" frameborder="0" noresize="noresize" scrolling="yes"></frame src="http:> Please go to http://www.clientwebsite.co.ukB <noframes></noframes> Thanks, Lu.
Technical SEO | | Webrevolve0 -
Open Site Explorer doesn't update correctly
We have been using OSE for a little over 2 Months now and our link demographics haven't changed although we have been getting lots of backlinks from other blogs and webpages. Google Webmaster Tools displays these links but OSE, even after the updates, doesn't.
Technical SEO | | wellbo
Our domain is about 1 Year old and has had indexed content on it since June this year. Google Webmaster Tools shows 24 Links to our domain but OSE only 3. The domain is http://www.wellbo.de0 -
What is the most likely reason we aren't ranking #1 for our keyword.
So we are targeting a keyword and we are ranking 2nd for it. Another company is ranking number 1. What is the best element to target for us to improve into position number one? Page authority: them 41, us 40. mozRank: them 5.52, us 3.38. mozTrust: them 5.86, us 5.58. mT/mR: them 1.1, us 1.4. Total Links: them 6571, us 68. Internal Links: them 1138, us 1. External Links: them 5431, us 63. Followed Links: them 6569, us 64. Nofollowed Links: them 2, us 4. Linking Root Domains: them 25, us 41. Broadkeyword usage in page title: them YES, us YES. KW in domain: them no, us partial. Exact anchor test links: them 161, us 21. % of links with exact anchor text: them 2%, us 30%. Linking Root domains with exact anchor text: them 2, us 11. Domain Authority: them 41, us 40. Domain MozRank: them 3.7, us 4.5. Domain MozTrust: them 3.8, us 4.5. External links to domain: them 22574, us 217. Linking root domains: them 50, us 48. Linking C-blocks: them 46, us 42. Tweets: them 1, us 12. FB shares: them 6, us 26.
Technical SEO | | Benj250