Forum Moderators: phranque

Message Too Old, No Replies

absolute.relative.both.none of the above.

Understanding redirect syntax...

         

Terabytes

11:59 pm on Oct 24, 2008 (gmt 0)

10+ Year Member



Hey all!

Ok...I'm trying to do a simple 301 redirect from one page to another. The files reside within a sub-directory structure, and I'd like to know it's going to be correct prior to trying it...

(I'd feel really stupid if it messed things up...)

are any of these correct?

RewriteEngine on
RewriteRule ^directory/oldfile\.htm$ .../directory/newfile.htm[R=301,L]

RewriteEngine on
RewriteRule ^directory/oldfile\.htm$ http://www.example.com/directory/newfile.htm[R=301,L]

is there an easier way?

Thanks for your time!
Tera

[edited by: jdMorgan at 1:29 am (utc) on Oct. 25, 2008]
[edit reason] example.com [/edit]

jdMorgan

1:28 am on Oct 25, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your second attempt was missing a space, but otherwise correct:

RewriteEngine on
RewriteRule ^directory/oldfile\.htm$ http://www.example.com/directory/newfile.ht[b]m [R[/b]=301,L]

If you're not already using mod_rewrite for other purposes, you could also use mod_alias for such a simple and unconditional redirect:

Redirect 301 /directory/oldfile.htm http://www.example.com/directory/newfile.htm

However, I do not recommend mixing mod_rewrite and mod_alias redirects -- The order of execution of these two modules can vary from server to server, and this could give unexpected results if, say, you changed hosts or they reconfigured your server and didn't tell you.

Jim

Terabytes

2:36 am on Oct 25, 2008 (gmt 0)

10+ Year Member



thanks so much! Exactly what I wanted...