How to force a trailing slash after the domain name
-
My campaign analysis is predictably listing domain.com and domain.com/ as repeated content. I've searched and searched but cannot find a way to force a trailing slash on the end of the domain name unless there's a file or directory after it..
Is there a way to accomplish this using .htaccess
-
I've gone with this .htaccess from your soulgorithm.com:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain.co.uk [NC]
RewriteRule (.*) http://domain.co.uk/$1 [L,R=301]RewriteCond %{REQUEST_URI} (.)/$
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.)/$ $1.php [L]RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]and I'm now getting the results I'm after. I'm getting similar behaviour to you in Firefox and IE, which explains a lot. I really appreciate the length you've gone to to help me here, so big thank you!
-
Test Site: soulgorithm.com
In the .htaccess file for this site:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.soulgorithm.com [NC]
RewriteRule (.*) http://soulgorithm.com/$1 [L,R=301]RewriteCond %{REQUEST_URI} (.)/$
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule (.)/$ $1.html [L]RewriteCond %{REQUEST_URI} (.)/$
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.)/$ $1.php [L]RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f [OR]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* %{REQUEST_FILENAME}/ [R=301,L]Which has the following effect:
soulgorithm.com > soulgorithm.com/
(slash is added, but only shows in IE and looks
likes its being stripped by Firefox but page
still loads fine)
soulgorithm.com/ > soulgorithm.com/
(loads fine, but only shows in IE and lookslikes its being stripped by Firefox but page
still loads fine)
soulgorithm.com/test > soulgorithm.com/test/
(loads fine, slash even shows in FF)
soulgorithm.com/test/ > soulgorithm.com.com/test/
(loads fine)
soulgorithm.com/testdir > soulgorithm.com/testdir/
(loads fine, slash even shows in FF)
soulgorithm.com/testdir/ > soulgorithm.com.com/testdir/
(loads fine, slash even shows in FF)
Let me know if this is what you see. I feel likes its getting close to working.
-
Thanks for sticking with this. Rather than me share the domain, do you know of any example sites using your code (or similar) which add a trailing slash after the domain name? I'd like to rule out my browser stripping it out.
-
Man, my mind is blown right now. I'm not giving up and hopefully someone else can chime in on this discussion and shed some light on this issue.
The code provided should have worked. Let me look into it some more. Also, if you don't mind what is the actual domain name?
-
That's right - nothing in there but the code you supplied.
-
Is this the only thing you have in your htaccess file?
if not, I would remove everything in the file and only have what i posted above, and let me know if it works.
-
Nope. Still no trailing slashes being added.
-
Try just the following:
Let me know if this works for you.
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !index.php RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://www.domain.com/$1/ [L,R=301]
-
Thanks for the reply, but this looks like all the other examples I've found. My .htaccess file looks like this :
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.)/$
RewriteRule ^(.)$ http://domain.co.uk/$1/ [L,R=301]But I get the following redirects going on:
domain.co.uk > domain.co.uk (ie nothing happens)
domain.co.uk/ > domain.co.uk (ie slash is removed)
domain.co.uk/page2 > domain.co.uk/page2 (ie nothing happens, but page loads)
domain.co.uk/page2/ > Internal server error
Any ideas?
-
Hi Clive.
Yes, you can easily do this with an .htaccess file, here is the code:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !(.*)/$ RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]
Just replace "domain.com" with your proper url for your site. This should be all that is needed.
Hope this helps!
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
-
Help: buy domain from Tradenames.com?
Hello to all, I'm Silvia. I am writing to ask if any of you know this site: tradenames.com. It is a domains broker. They contacted my client and would like to sell the .com business domain (my client currently has the .it). Does anyone know them? Thanks you for your help.
Technical SEO | | advmedialab0 -
How to get the most value out of an additional domain?
Hi, My company domain is wire.com. We recently also acquired wire.chat domain What's the best way to get value out of that additional domain? Wire is a messaging platform so "chat" is relevant but "wire chat" is not really a high volume term We don't have a whole lot of content, certainly no resources to build out additional valuable website Is simply redirecting traffic the only sensible to thing given the above restriction? Any technical issues to be mindful of? Thanks, Siim
Technical SEO | | Siim-at-Wire0 -
Domain Name appear as title no description in search result
Hello Everyone, I have an site suppose tatadocomo.com( imaginary name to just explain my query) .Two weeksa back everything was fine but now if i search any query that site ranks in SERPs I got domain name as title and url (homepage) beneath of title and after that 'click here to proceed'. .Tata Docomo tatadocomo.com Click here to Proceed Why I am seeing this result in SERPs? I checked robots.txt , everything is fine there. Please help me out. Thanks
Technical SEO | | Alick3000 -
Domain hacked and redirected to another domain
2 weeks ago my home page plus some others had a 301 redirect to another cloned domain for about 1 week (due to a hack).The original pages were then de-indexed and the new bad domain was indexed and in effect stole my rankings.Then the 301 was removed/cleaned from my domain and the bad domain was fully de-indexed via a request I made in WMT (this was 1 week ago).Then my pages came back into the index but without any ranking power (as if it's just in the supplemental index).It's been like this for a week now and the algorithms have not been able to correct it. So how do I get this damage undone or corrected? Can someone at Google reverse/cancel the 301 ranking transfer since the algorithms don't seem to be able to?I have the option to do a "Change of Address" in WMT from bad domain to my domain. But I don't think this would work properly because it says I also need to place a 301 on the bad domain back to mine. Would a change of address still work without the 301?Please advise/help what to do in order to get my rankings back to where they were.
Technical SEO | | Dantek0 -
Multiple (different) domains and canonicalisation
Hello, We've had experience with canonical tags for various domains before, such as tidying up product categories etc... However, can anyone point me to any guidelines about different domains using canonicalisation. For example: If I had the following sites, all with identical content - exampledomain.com completelydifferentdomain.net anothertotallydifferentdomain.com With canonical tags pointing to the first one (exampledomain.com), could this be harmful? Is it better to 301 redirect the other sites? Thanks
Technical SEO | | Sarbs0 -
301 from old domain to new domain
Hi, I need to create a 301 redirect for all internal pages located on organic7thheaven.com to the homepage of our new site at http://www.7thheavennaturals.com/ Currently internal pages of the old site such as the following are returning a page not found www.organic7thheaven.com/products/deepcleansing/miraclemud.asp Can anyone help me in setting up a .htaccess file for this problem please? Thanks
Technical SEO | | MJMarketing0 -
Should I create mini-sites with keyword rich domain names pointing to my main site?
Hi, I'm new to seomoz (and seo in general) and loving it so far. My main domain name is more of a brandname than a search engine friendly list of keywords. I rank well for some keywords I optimized for, and less so for the more competitive keywords. I was wondering if making one page minisites hosted on keyword rich domain names could help in this respect? What I want to do is just have a single page with a few paragraphs of content and links to the main site. I am not looking for links to boost the main site, just for the minisites to do better for several keywords. Will this help? Is this ok, or against some Google policy? Can this hurt the main site rankings? Thank you! **Edit: **I noticed that sites ranking above me on the first page for some keywords have much less on-page elements than my page, have about the same domain trust and also very little inbound links. The only factor I can see is the exact match of keywords in the domain name.
Technical SEO | | Eladla1 -
Slashes In Url's
If your cms has created two urls for the same piece of content that look like the following, www.domianname.com/stores and www.domianname.com/stores/, will this be seen as duplicate content by google? Your tools seem to pick it up as errors. Does one of the urls need 301 to the other to clear this up, or is it not a major problem? Thanks.
Technical SEO | | gregster10000