Welcome to WebmasterWorld Guest from 54.224.234.8
Forum Moderators: Ocean10000 & incrediBILL & phranque
From my woefully limited knowledge of Modrewrite I understand the above code ensures search engines only index http://site.com/ and not http://site.com/index.html
Can someone please advise how this should be applied for WWW addresses.
i.e. what rewrite code should be used in the htaccess file to ensure search engines only index www.site.com rather than www.site.com/index.html.
(All the code examples I've found just are for http://site.com/)
Many thanks
[edited by: jdMorgan at 3:35 am (utc) on Aug. 26, 2005]
[edit reason] De=linked. [/edit]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^website.com
RewriteRule ^(.*)$ http://www.website.com/$1 [R=permanent,L]
However, it does not redirect www.website.com/index.php to www.website.com/ ... can anyone say what I need to add to make that happen?
Any help would be really appreciated.
[edited by: jdMorgan at 3:33 am (utc) on Aug. 26, 2005]
[edit reason] De-linked. [/edit]
I had tested the code & it doesn't work - even with the mod you kindly suggested. What happens is that the redirection times out. When I did a header check it shows that the redirection is going into an endless loop as below:
SEO Consultants Directory Check Server Headers - Single URI Results
Current Date and Time: 2005-06-27T03:49:10-0800
User IP Address:
#1 Server Response: http://www.example.com/index.htm
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Date: Mon, 27 Jun 2005 10:49:10 GMT
Server: Apache
Location: http://www.example.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1
Redirect Target: http://www.example.com/
#2 Server Response: http://www.example.com/
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Date: Mon, 27 Jun 2005 10:49:10 GMT
Server: Apache
Location: http://www.example.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1
Redirect Target: http://www.example.com/
#3 Server Response: http://www.example.com/
HTTP Status Code: HTTP/1.1 301 Moved Permanently
Date: Mon, 27 Jun 2005 10:49:10 GMT
Server: Apache
Location: http://www.example.com/
Connection: close
Content-Type: text/html; charset=iso-8859-1
Redirect Target: http://www.example.com/
Above keeps repeating....
The htaccess file is as follows:
# -FrontPage-
IndexIgnore .htaccess */.?* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteRule ^index.htm$ / [R=301,L]
</IfModule>
AuthName www.example.com
AuthUserFile /www/site/_vti_pvt/service.pwd
AuthGroupFile /www/site/_vti_pvt/service.grp
Is there some error in the above causing this issue?
[edited by: jdMorgan at 3:37 am (utc) on Aug. 26, 2005]
[edit reason] De-linked. [/edit]
# Redirect client index.html requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]
#
# Force preferred domain for all requests to this server
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
GET /index.html HTTP/1.1
-or-
PROPPATCH /something.html HTTP/1.0
Jim
Many thanks for your reply which has finally solved the problem. :-)
I tried the code you suggested but it didn't immediately work when I plugged in my domain details.
RewriteEngine on
RewriteBase /
# Redirect client index.htm requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]
#
# Force preferred domain for all requests to this server
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.domain\.co\.nz
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
However it did work when I changed the order around & replaced the "Force preferred domain for all requests to this server" code with what I'd been using before. The code that seems to be working OK is this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain\.co.\nz [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
# Redirect client index.htm requests to "/"
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
RewriteRule ^index\.htm$ http://www.example.com/ [R=301,L]
Do you see any issues with doing it this way? Hoping I've not made a major cock up doing this because I didn't understand your comments that for reference, the pattern in that RewriteCond matches the form of THE_REQUEST, an example of which would be:
GET /index.html HTTP/1.1
-or-
PROPPATCH /something.html HTTP/1.0
Again, many thanks for your help
[edited by: jdMorgan at 3:41 am (utc) on Aug. 26, 2005]
[edit reason] De-linked. [/edit]
http://www.example.com/anything/index.htm
are redirected to the corresponding
http://www.example.com/anything/
--and also for two levels deep, three levels deep, etc.?
Can one rule handle zero levels of directories (above) and
also n levels of directories in the URL for n=1,2,3, ...?
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.htm\ HTTP/
RewriteRule index\.htm$ http://www.example.com/%1 [R=301,L]
Condition: Added a catch-all that precedes index.htm, so /anything that ends in index.html will match.
Rule: removed the ^ (hard begining of a line), but left the $ (end of a line), so any request that ends in index.htm will be compared. Also added %1 to the Rewrite URL, so if there is anything stored preceding index.htm, that will be returned in the redirect.
Hope this helps.
Justin
I have not tested this, so it may need a 'tweek' or two.
[edited by: jdMorgan at 3:42 am (utc) on Aug. 26, 2005]
[edit reason] Examplified. [/edit]
Options +FollowSymLinks
RewriteEngine on
#
# goal: add trailing slash to any URI if missing (w/ any num of dirs)
# if the URI is anything except a string of non-dots with final slash
RewriteCond %{REQUEST_URI} !^[^.]*/$
# then rewrite it as the entire string plus final slash
RewriteRule ^(.+)$ $1/ [R=301,L]
#
# goal: remove final index.htm if present (w/ any num of dirs)
# if the URI ends with a slash plus final string of index.htm
RewriteCond %{REQUEST_URI} ^.*/index\.htm$ [NC]
# then remove final string of index.htm
RewriteRule ^(.*/)index\.htm$ $1 [R=301,L]
Using THE_REQUEST ensures that the redirect happens only if the originally-requested URL is "/index.html" -- it won't happen as a result of the internal server processing that substitutes "index.html" for "/". Just for reference, the pattern in that RewriteCond matches the form of THE_REQUEST, an example of which would be