Forum Moderators: phranque

Message Too Old, No Replies

.htaccess 301 redirect for a https subdomain

.htaccess, 301 redirect, https, subdomain redirect to tld

         

stickygoblin

5:56 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



Hi,

I am trying to fix an issue that has occureed in a development area. Google has managed to index my https site while it is in the development area of the domain, this was primarily due to the SEO we were working on getting the site indexed before the client had finished the SEO.

We now have an issue with google linking to a dev site using https and the dev site does not have a certificate, the certificate is for the live www site.

Every time anyone clicks a link from google to the https deve site they get a certificate warning. I am trying to figure out a work around and thought that a straight redirect using https and 301 in a .htaccess file should do it:

currently my redirect looks like this:

redirectMatch 301 ^(.*)$ [{DOMAIN...] NAME HERE}.com
redirectMatch permanent ^(.*)$ [{DOMAIN...] NAME HERE}.com
redirectMatch 301 ^(.*)$ [{DOMAIN...] NAME HERE}.com
redirectMatch permanent ^(.*)$ [{DOMAIN...] NAME HERE}.com

If anyone could suggest a way of the redirecting these google links I would be grateful - even a DNS CNAME redirect isn't sorting out the issue.

Thanks
Sticky

jdMorgan

7:53 pm on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Consider a self-signed certificate for your dev site, then use your standard redirects.

Your code can be improved and compacted by taking advantage of the power of RedirectMatch and regular expressions:


RedirectMatch 301 ^/(.*)$ http://www\.example\.com/$1

Note that the "www." is now optional, and that the originally-requested URL-path is preserved.

If you need to preserve the original http/https request protocol, and both http and https requests resolve to the same .htaccess file on the dev server, then you'll need to use mod_rewrite:


Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{SERVER_PORT}>s ^(443>(s)¦80>s)$
RewriteRule (.*) http%2://www.example.com/$1 [R=301,L]

Jim

[edited by: jdMorgan at 11:18 pm (utc) on Mar. 10, 2009]