Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

The situation I have is that I have made a new website for a client, the URL format of which is http://newsite.com. The clients old website used SSL and had the URL format https://www.oldsite.co.uk. SSL is not necessary on the new site and thus has not been used.

The old site is ranking well in the search engines, and so for this reason the client would like to use 301 redirects to capture any requests made for the old pages and divert them to the equivalent pages on the new site ie. /contact.php on old site redirects to the new contact page.

The problem is that all of the search engines have indexed the https:// version of every url, and I need to redirect to a non SSL, standard http:// URL. In a nutshell what I need, is a way to catch any incoming URL with an https:// at the front, and somehow alter it to look for the http:// version of this URL instead.

The contents of my .htaccess file:

RewriteEngine on
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^nielbally\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.nielbally\.co\.uk$
RewriteRule ^/?$ "http\:\/\/artcourseswales\.com\/" [R=301,L]
share|improve this question
1  
What have you tried? –  Michael Hampton Mar 8 '13 at 12:37
    
Should we assume you're using Apache? –  nickgrim Mar 8 '13 at 12:37
    
Forgive me if I've missed anything that seems obvious, I don't have much experience with this stuff. –  Marc Mar 8 '13 at 12:52
    
This is what i've tried in the htaccess file: –  Marc Mar 8 '13 at 12:52
    
RewriteEngine on RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^nielbally\.co\.uk$ [OR] RewriteCond %{HTTP_HOST} ^www\.nielbally\.co\.uk$ RewriteRule ^/?$ "http\:\/\/artcourseswales\.com\/" [R=301,L] –  Marc Mar 8 '13 at 12:53

2 Answers 2

The best config is to create a virtual host for the old site name, with a redirect for all URLs.

<VirtualHost :443>
    ServerName oldsite.co.uk
    ServerAlias www.oldsite.co.uk

    RewriteRule ^(.*)$ http://newsite.co.uk$1
</VirtualHost>
share|improve this answer
    
Thanks. I'll try to implement this and see how I get on. –  Marc Mar 9 '13 at 16:34
    
I've tried this, and it doesnt seem to work. (other than if I request http:// version of the old site, which successfully redirects). –  Marc Mar 12 '13 at 12:58

Using RewriteRules in .htaccess files is tricky. What you are matching against is in this case not the URL requested, but the filename that apache thinks needs to be served in order to fulfil the request.

What you should do first is enable logging, as described here: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#logging

That way you'll know more about what is going on.

One feature of the rewrite engine that catches people unaware is the order RewriteRule and RewriteCond statements are executed in. Basically the RewriteRule must match first. If it matches, than the RewriteCond lines are evaluated from the top down, and only if they all pass is the substitution performed. In your RewriteRule you are matching against /? and I suspect that this never matches, and that thus the conditions you've added are never evaluated.

That said, creating a redirect in a virtual host is a better solution, but I don't know if you have access to the apache config file.

share|improve this answer
    
Thanks, really appreciate the advice. –  Marc Mar 9 '13 at 16:35
    
I've activated logging, but am not really sure where to go to view the logs. –  Marc Mar 12 '13 at 12:59
    
What Apache version are you using? Under 2.4 you set the loglevel for mod_rewrite with the LogLevel directive and the result you find in your apache erro logs. in previous versions you used Rewriteloglevel to tell what to log, and Reweritelog to tell mod_rewrite were to log to. –  Krist van Besien Mar 12 '13 at 16:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.