Welcome to WebmasterWorld Guest from 54.234.8.146

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Canonical Issue

How To Fix

     

leaseman

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

5+ Year Member



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.

milosevic

11:40 am on Nov 23, 2010 (gmt 0)

5+ Year Member



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.

jdMorgan

9:51 pm on Nov 30, 2010 (gmt 0)

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




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.

Jim
 

Featured Threads

Hot Threads This Week

Hot Threads This Month