0

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]
5
  • Should we assume you're using Apache?
    – nickgrim
    Mar 8, 2013 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, 2013 at 12:52
  • This is what i've tried in the htaccess file:
    – Marc
    Mar 8, 2013 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, 2013 at 12:53
  • Is that what you were looking for @Michael Hampton
    – Marc
    Mar 8, 2013 at 19:48

2 Answers 2

1

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>
2
  • Thanks. I'll try to implement this and see how I get on.
    – Marc
    Mar 9, 2013 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, 2013 at 12:58
0

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.

2
  • I've activated logging, but am not really sure where to go to view the logs.
    – Marc
    Mar 12, 2013 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. Mar 12, 2013 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .