Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



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!



Photo
- - - - -

Dual Purpose Htaccess


  • Please log in to reply
6 replies to this topic

#1 hilla4g

hilla4g

    HR 1

  • Members
  • Pip
  • 2 posts

Posted 25 October 2010 - 06:26 AM

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!




#2 Jill

Jill

    Recovering SEO

  • Admin
  • 32,963 posts

Posted 25 October 2010 - 06:48 AM

QUOTE
Both should help my rankings (I think?)


How so?

#3 qwerty

qwerty

    HR 10

  • Moderator
  • 8,619 posts
  • Location:Somerville, MA

Posted 25 October 2010 - 08:22 AM

Here's what I use:
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]

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 hilla4g

hilla4g

    HR 1

  • Members
  • Pip
  • 2 posts

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

#5 Zine

Zine

    HR 1

  • Members
  • Pip
  • 7 posts

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:
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]

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 MrPointy

MrPointy

    HR 1

  • Members
  • Pip
  • 1 posts

Posted 11 November 2010 - 10:37 AM

QUOTE(Zine @ Oct 28 2010, 12:32 PM) View Post
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


I followed the same example from another thread & have exactly the same outcome. My pages aren't redirecting as required. Any idea why?


#7 qwerty

qwerty

    HR 10

  • Moderator
  • 8,619 posts
  • Location:Somerville, MA

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:
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

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!