hkguile
hkguile

Reputation: 4359

redirecting a single https page to another http page

I want to redirect a old https page to new http page. I’ve tried this rule several times but it does not work:

RewriteRule ^https://www.mydomain.com/tc/page.html$ http://www.mydomain.com/index.php [L,R=301]

Any one know what is the problem?

Upvotes: 0

Views: 53

Answers (1)

Giacomo1968
Giacomo1968

Reputation: 26066

Your rewrite rule is this:

RewriteRule ^https://www.mydomain.com/tc/page.html$ http://www.mydomain.com/index.php [L,R=301]

Change it to this:

RewriteRule ^tc/page.html$ http://www.mydomain.com/index.php [L,R=301]

Also make sure RewriteEngine is set to On & there is a https check as well:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^tc/page.html$ http://www.mydomain.com/index.php [L,R=301]

The issue is when you attempt to match https://www.mydomain.com/tc/page.html it will try to match your domain on top of that specific path like this:

https://www.mydomain.com/https://www.mydomain.com/tc/page.html

Which is incorrect since that would never exist.

Also,while I am not clear on what your desktop environment is, it’s generally best to not trust browsers at first when testing stuff like this. I highly recommend using curl with the -I option to return the headers of a request to fully test it uncached & away from browser quirks like this.

For example, I tested this rule on my local Mac OS X MAMP setup like this:

curl -I http://localhost:8888/tc/page.html

And the curl -I output returned is:

HTTP/1.1 301 Moved Permanently
Date: Fri, 13 Jun 2014 02:08:53 GMT
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8y DAV/2 PHP/5.4.10
Location: http://www.mydomain.com/index.php
Content-Type: text/html; charset=iso-8859-1

The Location: field confirms this rule works as expected.

Upvotes: 1

Related Questions