Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Canonical Issue

How To Fix

5:18 pm on Nov 19, 2010 (gmt 0)

New User

5+ Year Member

joined:Mar 9, 2010
posts: 26
votes: 0

How do I fix the following issue:

You can get to my site by typing www.capitalsolutionsonline.net/
and www.capitalsolutionsonline.net/index AND www.capitalsolutionsonline.net/index.html

I'm already have the following code to direct the non www version to the www:

RewriteEngine on
rewritecond %{http_host} ^capitalsolutionsonline.net [nc]
rewriterule ^(.*)$ [capitalsolutionsonline.net...] [r=301,nc]

Question is what code to I add or what do I do to fix the other issues.

Thank you in advance.
11:40 am on Nov 23, 2010 (gmt 0)

Full Member

5+ Year Member

joined:Dec 30, 2009
posts: 249
votes: 0

Something like

RewriteRule ^(.*)/index(\.html|/)?$ http://www.example.com/$1 [R=301,L]

Note I didn't test this and wrote it off the top of my head, may need some tweaking and you may need a rewritecondition.

Two points:

Use example.com - your links won't get turned into URLs on here and it's easier to work with.

Follow coding standards - "rewritecond" is wrong - it's "RewriteCond" - as is r=301 - should be R=301. It may seem pedantic but it matters much more with Apache directives and mod_rewrite than other types of code. Yeah, the code still works on your server with the wrong case, but if you ever move servers you could find all this code suddenly stops working.
9:51 pm on Nov 30, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

RewriteEngine on
# Externally redirect direct client requests for named index pages
# in any directory to default index URL for that same directory
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.html([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.capitalsolutionsonline.net/$1 [R=301,L]
# Externally redirect all non-blank non-canonical hostname requests to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.capitalsolutionsonline\.net)?$
RewriteRule ^(.*)$ http://www.capitalsolutionsonline.net/$1 [R=301,L]

Note that these redirect rules are ordered from most-specific URL-paths and conditions to least-specific. Both rules should precede any and all internal (URL-to-filepath) rewrite rules.

The "complexity" of the first rule is needed to prevent an 'infinite' rewrite/redirect loop due to interaction with the DirectoryIndex directive which currently rewrites requests for the URL-path "/" to the filepath "/index.html". It is therefore necessary to check to be sure that the request for "/index.html" is coming straight from the HTTP client (e.g a browser), and is not the result of the DirectoryIndex rewrite.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members