Hi,
I want to setup 301 redirect on following urls to one url given below:
http://www.example.com
http://www.example.com/index.htm
http://example.com
http://example.com/index.htm
To
http://example.com
Is this possible using htaccess?
thanks
| SitePoint Sponsor |
Hi,
I want to setup 301 redirect on following urls to one url given below:
http://www.example.com
http://www.example.com/index.htm
http://example.com
http://example.com/index.htm
To
http://example.com
Is this possible using htaccess?
thanks
The old location of the file has to be the absolute path from the root of your server. The new location should use http. So for example, if you want to move a file called http://www.example.com from the root of your site to a subdirectory called products you would use :
The exact URL entered above: This will redirect the search spiders and users to the exact URL you entered in the “Redirect To:” example. For instance, if you somebody went to http://www.example.com/index.htm, they would go to http://example.com.
A directory below this one: Freaky Friday images aside, this redirects a parent directory to a child directory. For instance, if someone typed in http://www.example.com/index.htm to access the site and you wanted the request to be redirected to a child directory named “example.com”, then they would be sent to http://example.com.
OR
The old location of the file has to be the absolute path from the root of your server. The new location should use http. So for example, if you want to move a file called productreview.html from the root of your site to a subdirectory called example you would use :
Redirect 301 /http://www.example.com/index.htm http://example.com

Hi CW!
Welcome to SitePoint!
Well, that was a good though long-winded explanation then you missed the correct format of the Redirect statement:
Redirect {optional code} {internal absolute directory/file} {internal or external absolute redirection}
The point is that the Redirect statement you used should NOT have the protocol along with the internal absolute directory/file.
Diz,Code:Redirect 301 /http://www.example.com/index.htm [url]http://example.com
Why would you ever want to redirect http://example.com to http://example.com? That's an infinite loop!
Specificity:
Redefining your stated objective:
- Remove www. from domain
- Remove index.htm from the URI (IMHO, a bad thing to do especially as your host may have Apache configured to display the DirectoryIndex).
The short answer is "yes."
Try:
Of course, all this is explained in the mod_rewrite tutorial linked as an Article in my signature.Code:RewriteEngine on # Remove www RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L] # Remove index.htm from DocumentRoot RewriteRule ^index\.htm$ http://example.com [R=301,L]
Regards,
DK
David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
Client and (unpaid) WHB Ambassador
Updated mod_rewrite Tutorial Article (setup, config, test & write
mod_rewrite regex w/sample code) and Code Generator
Bookmarks