You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Wang Penghui <wa...@realss.com> on 2004/12/30 02:53:11 UTC

[users@httpd] Re: redirect lots of http:// to https:// with mod_rewrite

First of all, Thank you for your quick response.

My requirement is that, i want to redirect all the subdomains of a.cn, 
for example a.a.cn,b.a.cn
from http://a.a.cn http://b.a.cn to https://a.a.cn https://b.a.cn and if 
the request domain already
https:// ,ignored.

And the rewriterules i have writen seems not workable.

I am a newbie of rewrite, But i could not understand it clearly. Could 
someone pick me up?

Thanks very much

Sean T Allen wrote:
> Well first, you arent redirecting to an https
> 
> 2nd you all your rule says if if it is a subdomain of
> eoa.cn then pass it through as is...
> 
> it looks like i could pseudo your stuff out as...
> 
> If WELL FORMED
>    CONTINUE
> ELSE
>        and you have nothing to deal with the else...
> 
> And lastly you never address whether the incoming is a https or not
> so it should be taking https://blah.a.com to http://blah.a.com
> which i dont think is what you want either...
> 
> 
> 
> Wang Penghui wrote:
> 
>> Hi all:
>>     Sorry to ask so stupid question. Rewrite is so powerful that i 
>> could not manage it now.
>> Here is the question:
>> I have a domain named a.com, And i have lots of subdomains of it.
>> such as: a.a.com b.a.com c.a.com d.a.com etc...
>> I have bought a wildcard SSL certification (*.a.com) for all the 
>> subdomains.
>> But most of the users could not remember to type https:// before the 
>> domainnames.
>> So i have to redirect the *.a,com which the users inputed to 
>> https://*.a.com.
>> I want to use mod_rewrite to implement it.
>> Here is what i have writen in .htaccess:
>>
>> RewriteEngine   on
>> RewriteBase     /
>> RewriteCond     %{HTTP_HOST}    ^(w+)\.eoa\.cn [NC]
>> RewriteRule     ^$  http://%{HTTP_HOST} [R]
>>
>> But it seems working incorrect.
>> Could someone point out what wrong with it?
>>
>> Thanks in advance!
>>
>> Wang Penghui
>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server 
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


[users@httpd] Re: redirect lots of http:// to https:// with mod_rewrite

Posted by Wang Penghui <wa...@realss.com>.
Sean T Allen wrote:
> RewriteEngine On
> RewriteCond %{SERVER_PORT} !^443$
> RewriteCond %{HTTP_HOST} ^(.+)\.a\.cn$
> RewriteRule (.*) https://%1.a.cn$1 [L,R]
> 
> should work... i dont have a setup to really make it work or test it... 
> but it should
> you could make the 2nd rewrite condition more robust...
> right now is just does a.a.cn, b.a.cn etc
> and could do done to do a.a.a.cn or any infinite variety therein
> by something like ((.+)\.)+
> and adjusting the RewriteRule accordingly
> 
> let me know if you have any problems...
> 
How surprised it is.
Works very well.

Thank you for your help.

Wang Penghui
> Wang Penghui wrote:
> 
>> First of all, Thank you for your quick response.
>>
>> My requirement is that, i want to redirect all the subdomains of a.cn, 
>> for example a.a.cn,b.a.cn
>> from http://a.a.cn http://b.a.cn to https://a.a.cn https://b.a.cn and 
>> if the request domain already
>> https:// ,ignored.
>>
>> And the rewriterules i have writen seems not workable.
>>
>> I am a newbie of rewrite, But i could not understand it clearly. Could 
>> someone pick me up?
>>
>> Thanks very much
>>
>> Sean T Allen wrote:
>>
>>> Well first, you arent redirecting to an https
>>>
>>> 2nd you all your rule says if if it is a subdomain of
>>> eoa.cn then pass it through as is...
>>>
>>> it looks like i could pseudo your stuff out as...
>>>
>>> If WELL FORMED
>>>    CONTINUE
>>> ELSE
>>>        and you have nothing to deal with the else...
>>>
>>> And lastly you never address whether the incoming is a https or not
>>> so it should be taking https://blah.a.com to http://blah.a.com
>>> which i dont think is what you want either...
>>>
>>>
>>>
>>> Wang Penghui wrote:
>>>
>>>> Hi all:
>>>>     Sorry to ask so stupid question. Rewrite is so powerful that i 
>>>> could not manage it now.
>>>> Here is the question:
>>>> I have a domain named a.com, And i have lots of subdomains of it.
>>>> such as: a.a.com b.a.com c.a.com d.a.com etc...
>>>> I have bought a wildcard SSL certification (*.a.com) for all the 
>>>> subdomains.
>>>> But most of the users could not remember to type https:// before the 
>>>> domainnames.
>>>> So i have to redirect the *.a,com which the users inputed to 
>>>> https://*.a.com.
>>>> I want to use mod_rewrite to implement it.
>>>> Here is what i have writen in .htaccess:
>>>>
>>>> RewriteEngine   on
>>>> RewriteBase     /
>>>> RewriteCond     %{HTTP_HOST}    ^(w+)\.eoa\.cn [NC]
>>>> RewriteRule     ^$  http://%{HTTP_HOST} [R]
>>>>
>>>> But it seems working incorrect.
>>>> Could someone point out what wrong with it?
>>>>
>>>> Thanks in advance!
>>>>
>>>> Wang Penghui
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> The official User-To-User support forum of the Apache HTTP Server 
>>>> Project.
>>>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>>>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>>>> For additional commands, e-mail: users-help@httpd.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> The official User-To-User support forum of the Apache HTTP Server 
>>> Project.
>>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
>>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server 
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
> 
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Re: redirect lots of http:// to https:// with mod_rewrite

Posted by Sean T Allen <se...@usaherbals.com>.
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^(.+)\.a\.cn$
RewriteRule (.*) https://%1.a.cn$1 [L,R]

should work... i dont have a setup to really make it work or test it... 
but it should
you could make the 2nd rewrite condition more robust...
right now is just does a.a.cn, b.a.cn etc
and could do done to do a.a.a.cn or any infinite variety therein
by something like ((.+)\.)+
and adjusting the RewriteRule accordingly
 
let me know if you have any problems...

Wang Penghui wrote:

> First of all, Thank you for your quick response.
>
> My requirement is that, i want to redirect all the subdomains of a.cn, 
> for example a.a.cn,b.a.cn
> from http://a.a.cn http://b.a.cn to https://a.a.cn https://b.a.cn and 
> if the request domain already
> https:// ,ignored.
>
> And the rewriterules i have writen seems not workable.
>
> I am a newbie of rewrite, But i could not understand it clearly. Could 
> someone pick me up?
>
> Thanks very much
>
> Sean T Allen wrote:
>
>> Well first, you arent redirecting to an https
>>
>> 2nd you all your rule says if if it is a subdomain of
>> eoa.cn then pass it through as is...
>>
>> it looks like i could pseudo your stuff out as...
>>
>> If WELL FORMED
>>    CONTINUE
>> ELSE
>>        and you have nothing to deal with the else...
>>
>> And lastly you never address whether the incoming is a https or not
>> so it should be taking https://blah.a.com to http://blah.a.com
>> which i dont think is what you want either...
>>
>>
>>
>> Wang Penghui wrote:
>>
>>> Hi all:
>>>     Sorry to ask so stupid question. Rewrite is so powerful that i 
>>> could not manage it now.
>>> Here is the question:
>>> I have a domain named a.com, And i have lots of subdomains of it.
>>> such as: a.a.com b.a.com c.a.com d.a.com etc...
>>> I have bought a wildcard SSL certification (*.a.com) for all the 
>>> subdomains.
>>> But most of the users could not remember to type https:// before the 
>>> domainnames.
>>> So i have to redirect the *.a,com which the users inputed to 
>>> https://*.a.com.
>>> I want to use mod_rewrite to implement it.
>>> Here is what i have writen in .htaccess:
>>>
>>> RewriteEngine   on
>>> RewriteBase     /
>>> RewriteCond     %{HTTP_HOST}    ^(w+)\.eoa\.cn [NC]
>>> RewriteRule     ^$  http://%{HTTP_HOST} [R]
>>>
>>> But it seems working incorrect.
>>> Could someone point out what wrong with it?
>>>
>>> Thanks in advance!
>>>
>>> Wang Penghui
>>>
>>>
>>> ---------------------------------------------------------------------
>>> The official User-To-User support forum of the Apache HTTP Server 
>>> Project.
>>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>>> For additional commands, e-mail: users-help@httpd.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server 
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>
>
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server 
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>