httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Igor Cicimov <icici...@gmail.com>
Subject Re: [users@httpd] Rewrite rules not working
Date Fri, 08 Feb 2013 12:25:44 GMT
On Fri, Feb 8, 2013 at 10:51 AM, Andrew White <andrew@computersforall.com.au
> 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<http://www.askapache.com/htaccess/http-https-rewriterule-redirect.html>
>  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]

Mime
View raw message