• Hi, was reading somethings on SEO and was told that I should have a 302 redirect rule set up in the .htaccess file to direct all http:// traffic to http://www. locations.

    I can access the .htaccess file and have tried to add in the basic lines for a 301 redirect, but that failed BIG time.

    I am using permalinks and I know that, that writes some fancy scripting on the .htaccess file for that.

    I am curious of how I would write this rule and where in the file do I place it (before or after anything)

    My Stats:
    Server OS: Linux
    Apache: 1.3.34(Unix)
    Perl: 5.8.5
    PHP: 4.4.1
    MySQL: 4.1.14
    WodPress: 1.5.2

Viewing 4 replies - 1 through 4 (of 4 total)
  • The www prefix has not bearing on search engine rank on it’s own. Keep in my that to a search engine, http://www.example.com and example.com may be two different sites. So if you’re already indexed with the www, then you can use the following rules, otherwise it really makes no difference in terms of SEO, more of a personal preference for the webmaster I suppose.

    This rule should add the www prefix:

    RewriteRule ^(.*) http://www.YOURDOMAIN.EXT [L,R=301]

    and this one should add the trailing slash:

    # If requested resource does not exist as a file
    RewriteCond %{REQUEST_FILENAME} !-f
    # and does not end with a period followed by a filetype
    RewriteCond %{REQUEST_URI} !..+$
    # and does not end with a slash
    RewriteCond %{REQUEST_URI} !/$
    # then add a trailing slash and redirect
    RewriteRule (.*) $1/ [R=301,L]

    Good luck,
    Michael.

    Thread Starter bazil

    (@bazil)

    you had stated:
    “and this one should add the trailing slash:”

    is there an advantage to the trailing slash?

    I don’t think there is any specific technical advantage to it, though I may be wrong, it just keeps everything neat and tidy. I’m especially retentive on trivial details like that, so I always force the trailing slash.

    In terms of SEO, I have read that it is ‘better’ to have no file extensions, so if you change structure or SSSL’s (ie say ASP to PHP), the extensionless URI is still the correct one. Just keep things consistent, as long as the search bot can get to the page, then it’s happy.

    Cheers,
    Michael.

    Hi niziol –

    Thanks for the great post, for someone like me who doesn’t understand what’s going on with .htaccess it’s great for someone to spell it out for me 🙂

    One question, though… If 2 people link to my site, one to http://www.mydomain.com and one to http://www.mydomain.com/, will google see these as two separate sites or does the redirect tell google to see them as the same site?

    thanks,

    guy

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘301 redirect on Apache server?’ is closed to new replies.