Forum Moderators: phranque

Message Too Old, No Replies

301 redirect htaccess

domain.com > www.domain.com

         

soapystar

4:29 pm on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Anyone tell me how to write a 301 in htaccess to redirect [mydomain.com...] to [mydomain.com....] cant seem to get it rght....

leoo24

4:48 pm on Feb 14, 2004 (gmt 0)

10+ Year Member



RewriteEngine On
RewriteRule ^(.*)$ [newdomain.com...] [R=301,L]

:)

claus

5:10 pm on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before the RewriteRule, you might want to add a test to make sure that the domain is actually spelled without "www." before you make the redirect - otherwise you will also redirect those requests that already use the "www."

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I removed "^" and "$" from the RewriteRule leoo24 posted, i don't think they were wrong, but i don't think they made much of a difference either ;)

soapystar

5:20 pm on Feb 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



claus, can i call you santa? works like a charm, thanks. Leoo thanks for your help too.

theblade24

5:15 pm on Mar 15, 2004 (gmt 0)

10+ Year Member



Is there a method to do the above, however, I need it to exclude a request for [example.com?...]

In other words I'd like to change example.com to www.example.com except when referenced as a secure server of [example.com....]

Can that be done?

closed

3:17 am on Mar 17, 2004 (gmt 0)

10+ Year Member



Yes. To do that, I'd check
SERVER_PORT
. HTTPS' default port is 443.

theblade24

11:16 am on Mar 17, 2004 (gmt 0)

10+ Year Member



I'm not a wiz here unfortunately.

How would you change the following to accomplish that?

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) [example.com...] [R=301,L]

closed

3:36 pm on Mar 17, 2004 (gmt 0)

10+ Year Member



I'll let you try first.

You may need these:

mod_rewrite [httpd.apache.org]
Regular expressions [etext.lib.virginia.edu]

The mod_rewrite link also has a link to a URL rewriting guide at the end.

cline

12:24 am on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



claus, your code works beautifully. Thank you!

soapystar

7:04 am on Apr 7, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



claus, your code works beautifully. Thank you!

i already told him that :-)