RE: Rewrite rules not working

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To have ssl teaffic you need ssl vhost configured. Do you have it? Also please explain where have you put the rules and show us the detailed config. Sorry for top posting im on the phone.

On 11/02/2013 11:46 AM, "Andrew White" <andrew@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hey Igor,

 

Thanks for that.

 

I’ve turned it on and I think I’ve identified the problem, however I still can’t quite find a fix. In the logs if I am using my original condition/rule and use mysite.com.au/test I see the following:

 

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri 'test'

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri 'test'

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri 'test'

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (2) [perdir /home/website/public_html/] rewrite 'test' -> 'http://www.mysite.com.au/test'

10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http://www.mysite.com.au/test

 

However when I run it against just mysite.com.au I see:

 

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (2) [perdir /home/website/public_html/] rewrite '' -> '://www.mysite.com.au/'

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] add per-dir prefix: ://www.mysite.com.au/ -> /home/website/public_html/://www.mysite.com.au/

10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http:/.makeitmine.com.au/home/website/public_html/://www.mysite.com.au/

 

Note that the environment variable I’m trying to set (SSL on/off) isn’t being set. As such, it’s not seeing the http/https prefix and assuming it’s a relative internal path!

 

When I’m trying to set the environment variable, I use the following code:

 

       RewriteCond %{HTTPS} =on

        RewriteRule ^(.+)$ - [env=ps:https]

        RewriteCond %{HTTPS} !=on

        RewriteRule ^(.+)$ - [env=ps:http]

 

The RegEx of ^(.+)$ expects a minimum of 1 character, which there is not to match! I modified it as follows:

 

       RewriteCond %{HTTPS} =on

        RewriteRule ^(.*)$ - [env=ps:https]

        RewriteCond %{HTTPS} !=on

        RewriteRule ^(.*)$ - [env=ps:http]

 

And now it matches, even on 0 characters!

 

Thanks again for your help, problem solved :)

 

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (2) [perdir /home/website/public_html/] rewrite '' -> 'http://www.mysite.com.au/'

10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http://www.mysite.com.au/

 

From: Igor Cicimov [mailto:icicimov@xxxxxxxxx]
Sent: Monday, 11 February 2013 10:58 AM
To: users
Subject: RE: Rewrite rules not working

 

RewriteLog i think was the statement but please check the docs too

On 11/02/2013 10:34 AM, "Andrew White" <andrew@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi Igor,

 

Thanks for your help, but this doesn’t seem to work.

 

From a bit of testing, it looks like the RewriteRule starting with “/” simply doesn’t catch anything.

 

Any other ideas? Or are there any logs I can check/set up for mod_rewrite?

 

Thanks all!

 

Andrew

 

From: Igor Cicimov [mailto:icicimov@xxxxxxxxx]
Sent: Friday, 8 February 2013 11:26 PM
To: users
Subject: Re: Rewrite rules not working

 

 

 

On Fri, Feb 8, 2013 at 10:51 AM, Andrew White <andrew@xxxxxxxxxxxxxxxxxxxxxx> wrote:

Hi all,

I've been writing a rewrite rule to try and redirect all of our traffic from mysite.com.au to www.mysite.com.au. I also need to conditionally redirect depending on SSL enabled or not.

I've hacked on a bit from askapache.com to create a variable that holds either http or https dependently. Below is the code I'm using:

 

    RewriteCond %{HTTPS} =on
    RewriteRule ^(.+)$ - [env=ps:https]
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.+)$ - [env=ps:http]
    RewriteCond %{HTTP_HOST} ^mysite\.com\.au(.*)$ [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^(.*)$ %{ENV:ps}://www.mysite.com.au/$1 [L,R=301]

 

This works fine for URLs with paths (e.g. mysite.com.au/foo redirects to www.mysite.com.au/foo) and does the http and https switch fine.

However when just accessing the domain (just mysite.com.au) it redirects tohttp://www.mysite.com.au/home/website/public_html/:/www.mysite.com.au/

I'm sure it's something very small and basic I'm missing - if someone could point it out, that'd be appreciated.

Thanks!

Andrew

 

Try this way

RewriteCond %{HTTP_HOST} ^mysite\.com\.au$ [NC]
    RewriteCond %{HTTP_HOST} !^$
    RewriteRule ^/(.*)$ %{ENV:ps}://www.mysite.com.au/$1 [L,R=301]

 


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux