Forum Moderators: phranque

Message Too Old, No Replies

Why doesn't my 301 redirect work?

         

knights1

3:18 pm on Jan 2, 2006 (gmt 0)

10+ Year Member



I took my .htaccess file and added this underneath what was already there.

redirect 301 / [domain.com...]

and it isn't working? Also, will this redirect all sub pages (ie. www.site.com/tool.html to www.domain.com/tool.html?

I'm using a linux server.

Derek

Coil

6:03 am on Jan 3, 2006 (gmt 0)

10+ Year Member



The syntax is incorrect.

Also, don't just use

redirect
as some browsers might not support that. Use a real one:

To do a 301 redirect, use this:


Options All
RewriteEngine on
RewriteRule ^(.*)/?$ http://domain.com/$1 [R=301,L]

EDIT: $1 is the subpage if any.
Let me know if that works.

R=301 is your redirect type
L means it stops there and redirects, which is what you want.

jdMorgan

6:18 am on Jan 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, assuming that you're redirecting to a different domain on a different server, then

Redirect 301 / http://www.domain.c[b]om/[/b]

should work just fine. The Redirect directive uses prefix-matching, and any trailing part of the requested local URL-path that is not specified in your directive will be carried over to the new URL. See Apache mod_alias [httpd.apache.org] for more info.

If you are redirecting to a domain that is actually on the same server, then you will need to test the requested hostname, and only do the redirect if it is the 'wrong one'. This requires you to use mod_rewrite [httpd.apache.org] instead of mod_alias, though:


Options +FollowSymLinks
RewriteEngine on
# if not the correct domain
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com [NC]
# redirect to correct domain
RewriteRule (.*) http://domain.com/$1 [R=301,L]

Jim

Marcia

6:36 am on Jan 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>>Redirect 301 / [domain.com...]

Works for me, even when it's just a single page being redirected to another domain (which has a little more added, but same syntax).

mod_alias is much easier to understand use than mod_rewrite, imho.

jdMorgan

7:38 am on Jan 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> mod_alias is much easier to understand use than mod_rewrite, imho.

Yes it is, and as noted above, a simple Redirect 301 will work as long as the server where the code is installed is different than the server for the domain to be redirected to. However, if the two domains resolve to the same server, then you need mod_rewrite's ability to test the requested hostname and redirect conditionally.

"Make everything as simple as possible, but no simpler" - A. Einstein.

Jim

Shaundm

7:53 pm on Jan 5, 2006 (gmt 0)

10+ Year Member



Hi
What file do you write the redirect code in? Am having trouble?
Shaun

KeywordCountry

8:09 am on Jan 13, 2006 (gmt 0)

10+ Year Member



htaccess file. (This file has no extension and resides at the root folder of your FTP)

pokermac

11:53 pm on Feb 4, 2006 (gmt 0)

10+ Year Member



help.

I need to redirect from .mac (old server).

There is no way to do .htaccess from the .mac server

What is the most SEO friendly way of doing a redirect apart from .htaccess?

- meta refresh?
- flash?
- javascript?

help! thanks.