You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Vivek Nambiar <vi...@gmail.com> on 2012/03/02 15:59:26 UTC

[users@httpd] Rewrite Rule

Hi Experts,

I have a quick question regarding rewrite rule.

My aim is to redirect users http URL to https URL.

Like suppose the user enters the URL as follows in the web browser

http://servername:port/myapp then it should redirect itself to
https://servername:SSLport/myapp.

I have added the following rewrite condition and rule in my httpd.conf file

RewriteCond %{SERVER_PORT} PORT
RewriteRule ^/(.*)$ https://%{SERVER_NAME}:SSLPORT/$1 [R,L].

The rewrite rule works only if I use the url as http://servername:port/myapp/
(i have to add a "/" infront of my application)

if I use http://servername:port/myapp then the rewrite is done only for the
port,that is it changes to http://servername:sslport/myapp (http does not
change to https).

Thanks in advance for your help.

Re: [users@httpd] Rewrite Rule

Posted by Vivek Nambiar <vi...@gmail.com>.
Hi,

Thank you and that works fine,but I would still like to know why rewrite
rule does not work.May be I am not using the write parameters??.

Regards


On Fri, Mar 2, 2012 at 9:08 PM, Mathijs <ma...@gmail.com> wrote:

> The cleanest way of doing this, doesn't even need mod_rewrite. Just define
> two virtualhosts, one for the non-ssl host and one for the ssl host:
>
> NameVirtualHost *:80
> <VirtualHost *:80>
>    ServerName www.example.com
>    Redirect permanent / https://www.example.com/
> </VirtualHost>
>
> NameVirtualHost *:443
> <VirtualHost *:443>
>    ServerName www.example.com
>    DocumentRoot /path/to/htdocs/
>    SSLEngine On
>    ...etc...
> </VirtualHost>
>
> On Fri, Mar 2, 2012 at 3:59 PM, Vivek Nambiar <vi...@gmail.com>wrote:
>
>> Hi Experts,
>>
>> I have a quick question regarding rewrite rule.
>>
>> My aim is to redirect users http URL to https URL.
>>
>> Like suppose the user enters the URL as follows in the web browser
>>
>> http://servername:port/myapp then it should redirect itself to
>> https://servername:SSLport/myapp.
>>
>> I have added the following rewrite condition and rule in my httpd.conf
>> file
>>
>> RewriteCond %{SERVER_PORT} PORT
>> RewriteRule ^/(.*)$ https://%{SERVER_NAME}:SSLPORT/$1 [R,L].
>>
>> The rewrite rule works only if I use the url as http://servername:port/myapp/
>> (i have to add a "/" infront of my application)
>>
>> if I use http://servername:port/myapp then the rewrite is done only for
>> the port,that is it changes to http://servername:sslport/myapp (http
>> does not change to https).
>>
>> Thanks in advance for your help.
>>
>
>
>
> --
> Gr,
>
> Mathijs
>

Re: [users@httpd] Rewrite Rule

Posted by Mathijs <ma...@gmail.com>.
The cleanest way of doing this, doesn't even need mod_rewrite. Just define
two virtualhosts, one for the non-ssl host and one for the ssl host:

NameVirtualHost *:80
<VirtualHost *:80>
   ServerName www.example.com
   Redirect permanent / https://www.example.com/
</VirtualHost>

NameVirtualHost *:443
<VirtualHost *:443>
   ServerName www.example.com
   DocumentRoot /path/to/htdocs/
   SSLEngine On
   ...etc...
</VirtualHost>

On Fri, Mar 2, 2012 at 3:59 PM, Vivek Nambiar <vi...@gmail.com>wrote:

> Hi Experts,
>
> I have a quick question regarding rewrite rule.
>
> My aim is to redirect users http URL to https URL.
>
> Like suppose the user enters the URL as follows in the web browser
>
> http://servername:port/myapp then it should redirect itself to
> https://servername:SSLport/myapp.
>
> I have added the following rewrite condition and rule in my httpd.conf file
>
> RewriteCond %{SERVER_PORT} PORT
> RewriteRule ^/(.*)$ https://%{SERVER_NAME}:SSLPORT/$1 [R,L].
>
> The rewrite rule works only if I use the url as http://servername:port/myapp/
> (i have to add a "/" infront of my application)
>
> if I use http://servername:port/myapp then the rewrite is done only for
> the port,that is it changes to http://servername:sslport/myapp (http does
> not change to https).
>
> Thanks in advance for your help.
>



-- 
Gr,

Mathijs

Re: [users@httpd] Rewrite Rule

Posted by Rainer Frey <ra...@inxmail.de>.
On 02.03.2012, at 15:59, Vivek Nambiar wrote:
> http://servername:port/myapp then it should redirect itself to https://servername:SSLport/myapp.
> 
> I have added the following rewrite condition and rule in my httpd.conf file
> 
> RewriteCond %{SERVER_PORT} PORT
> RewriteRule ^/(.*)$ https://%{SERVER_NAME}:SSLPORT/$1 [R,L].
> 
> The rewrite rule works only if I use the url as http://servername:port/myapp/ (i have to add a "/" infront of my application)
> 
> if I use http://servername:port/myapp then the rewrite is done only for the port,that is it changes to http://servername:sslport/myapp (http does not change to https).

Add a RewriteLog, and set a RewriteLogLevel of, as a start, 4. Make a single request, look at the output. If you don't see the problem yourself then, post the log output for that one request, and your full rewrite config. Maybe there's a different rule catching the URL first.

Rainer 
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org