Hi
I'm after an htaccess file that will perform two redirects, but I don't know enough about coding to sort it out.
Firstly I want anyone visiting mydomain.com to 301 to www.mydomain.com/ throughout the site.
Secondly I want anyone visiting www.mydomain.com/index.shtml to be redirected to www.mydomain.com/
Both should help my rankings (I think?) but I can't find code that does both?
Thank you!
Are you a Google Analytics enthusiast?
Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE!

www.CustomReportSharing.com
From the folks who brought you High Rankings!
More SEO Content
International SEM | Social Media | Search Friendly Design | SEO | Paid Search / PPC | Seminars | Forum Threads | Q&A | Copywriting | Keyword Research | Web Analytics / Conversions | Blogging | Dynamic Sites | Linking | SEO Services | Site Architecture | Search Engine Spam | Wrap-ups | Business Issues | HRA Questions | Online Courses
Dual Purpose Htaccess
Started by
hilla4g
, Oct 25 2010 06:26 AM
6 replies to this topic
#1
Posted 25 October 2010 - 06:26 AM
#2
Posted 25 October 2010 - 06:48 AM
QUOTE
Both should help my rankings (I think?)
How so?
#3
Posted 25 October 2010 - 08:22 AM
Here's what I use:
You'll need to change "url.com" to your domain name and add shtml to the list of file types.
But this isn't about rankings. It's just about avoiding canonicalization issues.
CODE
# Force requests for named index files to drop the index file filename, and force www:
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.url.com/$1 [R=301,L]
#
# Redirect non-www to www:
#
RewriteCond %{HTTP_HOST} ^url\.com [NC]
RewriteRule (.*) http://www.url.com/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.url.com/$1 [R=301,L]
#
# Redirect non-www to www:
#
RewriteCond %{HTTP_HOST} ^url\.com [NC]
RewriteRule (.*) http://www.url.com/$1 [R=301,L]
You'll need to change "url.com" to your domain name and add shtml to the list of file types.
But this isn't about rankings. It's just about avoiding canonicalization issues.
#4
Posted 25 October 2010 - 01:55 PM
Hi
Thanks for the answer - I'll give it a try. Sure, it's not about direct rankings (I guess I was too ambiguous) but it should prevent Google itemising effectively 4 different URLs with the same content (www and non-www, and /index.shtml and just /). This in turn should lessen the division of authority between the pages. I'm not expecting a huge leap in rankings (that would just be silly!) but simply a reliable way to avoid the commonest error which I've been guilty of so far!
Cheers
Thanks for the answer - I'll give it a try. Sure, it's not about direct rankings (I guess I was too ambiguous) but it should prevent Google itemising effectively 4 different URLs with the same content (www and non-www, and /index.shtml and just /). This in turn should lessen the division of authority between the pages. I'm not expecting a huge leap in rankings (that would just be silly!) but simply a reliable way to avoid the commonest error which I've been guilty of so far!
Cheers
#5
Posted 28 October 2010 - 07:32 AM
Qwerty - I've used the example you gave for a site I'm working on.
The code I've used is:
Which has been put on the server as a .htaccess file - yet if I visit www.example.co.uk/index.htm - it still stays as /index.html, and not redirecting to just the domain name - can you help?
Regarding the non www route - I understood that you had to implement a blank 'A' record to match the www one to be able to do this - is this true?
Any help would be appreciated!
Mike
The code I've used is:
CODE
# Force requests for named index files to drop the index file filename, and force www:
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.example.co.uk/$1 [R=301,L]
#
# Redirect non-www to www:
#
RewriteCond %{HTTP_HOST} ^example\.co.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.(html?|php)(\?[^\ ]*)?\ HTTP/
RewriteRule ^(([^/]*/)*)index\.(html?|php)$ http://www.example.co.uk/$1 [R=301,L]
#
# Redirect non-www to www:
#
RewriteCond %{HTTP_HOST} ^example\.co.uk [NC]
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]
Which has been put on the server as a .htaccess file - yet if I visit www.example.co.uk/index.htm - it still stays as /index.html, and not redirecting to just the domain name - can you help?
Regarding the non www route - I understood that you had to implement a blank 'A' record to match the www one to be able to do this - is this true?
Any help would be appreciated!
Mike
#6
Posted 11 November 2010 - 10:37 AM
Qwerty - I've used the example you gave for a site I'm working on.
Which has been put on the server as a .htaccess file - yet if I visit www.example.co.uk/index.htm - it still stays as /index.html, and not redirecting to just the domain name - can you help?
Regarding the non www route - I understood that you had to implement a blank 'A' record to match the www one to be able to do this - is this true?
Any help would be appreciated!
Mike
Which has been put on the server as a .htaccess file - yet if I visit www.example.co.uk/index.htm - it still stays as /index.html, and not redirecting to just the domain name - can you help?
Regarding the non www route - I understood that you had to implement a blank 'A' record to match the www one to be able to do this - is this true?
Any help would be appreciated!
Mike
I followed the same example from another thread & have exactly the same outcome. My pages aren't redirecting as required. Any idea why?
#7
Posted 11 November 2010 - 10:44 AM
Sorry, no. I copied that code from somewhere myself, and I've used it probably on about a dozen sites, and it's never failed me. I don't know enough about what the code is designed to do to even guess at why it's not working for you.
One question, Zine. You wrote:
I don't know if that's a typo or not. Is your home page index.htm or index.html, and does the code in the .htaccess refer to the same one?
One question, Zine. You wrote:
QUOTE
I visit www.example.co.uk/index.htm - it still stays as /index.html
I don't know if that's a typo or not. Is your home page index.htm or index.html, and does the code in the .htaccess refer to the same one?
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users








