Forum Moderators: phranque

Message Too Old, No Replies

Quick check . . . .

301 redirect

         

rocknbil

6:44 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Redirect .org and .net to www.example.com. WWW is required as that's where all the serps are pointing. BUT . . . since https is set up on non-www, leave https alone.

Appears to be working, tested in all browsers, anything amiss here?

RewriteEngine On

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.example\.com
## For included files - JS, CSS, etc. stored in "includes"
RewriteCond %{REQUEST_URI}!\/includes\/
RewriteCond %{HTTPS}!^443$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

jdMorgan

9:06 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks OK to me.

You can save yourself some time the next time you test; Since this code executes server-side, you only need to test in one browser, except for any code whose function depends on the HTTP_USER_AGENT variable.

Jim

rocknbil

9:17 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We immediately got a complaint from an AOL customer, "I can't get past [some page] and need to place an order." I know "correlation does not always mean causation" but wonder if this could have been the cause?

Wouldn't this be more prudent if the task is only to direct .net and .org to .com? (above code was with WITH spaces before! of course . . . )

RewriteEngine On

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

The https is only used once the visitor is actually in the site.

jdMorgan

9:53 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, missed this:

RewriteEngine On
#
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
## For included files - JS, CSS, etc. stored in "includes"
RewriteCond %{REQUEST_URI} !/includes/
RewriteCond %{[b]SERVER_PORT[/b]} !^443$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Your second version won't work. If you want to go that route, try:

RewriteEngine On
#
RewriteCond %{HTTP_HOST} (www\.)?example\.net [b][OR][/b]
RewriteCond %{HTTP_HOST} (www\.)?example\.org
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Jim

[edited by: jdMorgan at 9:54 pm (utc) on June 7, 2007]

rocknbil

10:14 pm on Jun 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you again, sir. :-)

[edit - scratch this]But for whatever reason, the redirect does not work.[/scratch]
(It works perfectly, was checking an .htaccess in a different directory. Doh.)

Does this make better sense for the task, or no? I'm always wary of doing an "everything except" in my programming because there may be something in that everything I hadn't thought of.

The %{HTTPS}!^443$ I picked up from some code around here . . . somewhere . . . case in point. :-)