Forum Moderators: phranque

Message Too Old, No Replies

URLS getting redirected to HTTPS when i try to redirect to HTTP

         

krish1

6:04 am on Aug 27, 2012 (gmt 0)

10+ Year Member



Hi Everyone,

I have a requirement where i need to redirect URLS from one domain(www.example.com) to another domain(www.example1.com)

the script written is as follows,

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{REQUEST_URI} !^/$ [NC]
RewriteCond %{REQUEST_URI} !^/ab/new/home$ [NC]
RewriteCond %{REQUEST_URI} ^/ab/new/* [NC]
RewriteRule (.*) http://example1.com$1 [L,R=301]

By putting this script, whenever i hit a URL with http://example.com/ab/new/former .. etc the URL is getting redirected to https://example1.com/ab/new/former
instead of http://example1.com/ab/new/former


However when i put the rule as (please see the additional slash(/))
RewriteRule (.*) http://example1.com/$1 [L,R=301]

the URL is getting redirected to http://example1.com//ab/new/former

[edited by: incrediBILL at 7:19 am (utc) on Aug 27, 2012]
[edit reason] unlinked URLs [/edit]

phranque

12:10 am on Aug 28, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, krish1!

are your mod_rewrite directives in the .htaccess file in your document root directory or in the server config file?

lucy24

4:58 am on Aug 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I sure hope it's the config file, because that's where you get your requests with leading slash. Capture the slash, tack it onto an additional slash, and there's your two of them.

Which doesn't help the real question: You seem to have some kind of weird double markedness going on, where your server is confused about where it is and is throwing in an extra slash for security.

What happens if you try Option C?

RewriteRule ^/(.*) http://example.com/$1 [L,R=301]

:: fingers crossed ::

phranque

5:50 am on Aug 28, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i would use a header checker to see if the redirect from http://example.com/ab/new/former to [example1.com...] is happening in 1 or more hops.

you have additional issues with the regular expressions in your RewriteCond directives but let's understand what is really happening first.

assuming you have access to the server config file you may also have the option of turning on rewrite logging while testing your configuration.
the directives used for rewrite logging changed with apache 2.4, so you'll need the version information before you figure that out.

g1smd

10:18 am on Aug 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



new/* matches new and new/ and new/////////////

I expect you have another ruleset performing a rewrite that is being actioned before this rule doing the redirect.