Forum Moderators: phranque

Message Too Old, No Replies

https versus http redirect handling

Do https requests have to be matched specifically?

         

pcproffitt

6:01 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



I recently changed my digital cert for a site so that the base url is mydomain.com instead of www.mydomain.com. Now I need to change the .htaccess file to push search engine stored urls from [mydomain.com...] to [mydomain.com....]

Code in .htaccess is:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^mydomain\.com [NC]
RewriteRule ^(.*) [mydomain.com...] [R=301,L]

This correctly pushes [mydomain.com...] to [mydomain.com....] However, it won't push [mydomain.com...] to [mydomain.com....]

I'm missing something somewhere. The SSL and non-SSL accesses share the same directory (not separate directories).

Thanks,

jdMorgan

8:32 pm on Aug 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your SSL files may indeed be stored to a different filepath. If so, you will need a "copy" of the rules in that path's top .htaccess file as well.

Otherwise, be very sure that you've deleted your browser cache before testing any new server-side code. Otherwise, your browser will show you stale cached pages and server responses. "Forcing" a page reload is not sufficient in most cases -- delete the cache completely.

Your code itself does not 'look at' SSL versus non-SSL, and is correct as far as it goes. So it should invoke the redirects as you desire as long as it is located in a .htaccess file along the directory-path to the requested resource; Be very sure about your rule order if you have additional RewriteRules in this file. For that matter, problems may also be caused by mixing mod_alias directives with mod_rewrite, because in doing so, you lose control over directive execution order.

Should you wish to canonicalize the hostname without forcing https, you can use

RewriteCond %{HTTP_HOST} !^mydomain\.com$
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://mydomain.com/$1 [R=301,L]

That's got nothing to do with your current issue, though...

Jim

pcproffitt

8:43 pm on Aug 26, 2010 (gmt 0)

10+ Year Member



The answer to this may be that the redirect is actually working. The problem is that the ssl certificate is being evaluated PRIOR to any mod-rewrite directive evaluation. So the only solution if you take a site from a certificate for www.mydomain.com to mydomain.com is to wait for search engines to reindex the site and update all the indexed pages. If there's a different answer I'd like to hear it. If not I can still have the certificate reissued for www.mydomain.com.