You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by James Jones <ja...@freedomnet.co.nz> on 2010/10/18 19:43:49 UTC

[users@httpd] mod_rewrite fails

  can someone explain why neither of these rules work:_


Rule 1:_
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(.*)(?!wp-login) [NC]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]


_Rule 2:_
RewriteCond %{REQUEST_URI} ^wp-login(.*)$
RewriteRule .? - [S=1]
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


We are trying to rewrite all pages back to http except for one special 
page: wp-login. Any help would be greatly appreciated.

-- 
James Jones
+1-413-667-9199
james@freedomnet.co.nz


Re: [users@httpd] mod_rewrite fails

Posted by Eric Covener <co...@gmail.com>.
> everything going to https://somesite.com needs to go to http://somesite.com
> so for example https://somesite.com/somedir/somefile.php?somevar=someval
> needs to be redirected to
> http://somesite.com/somedir/somefile.php?somevar=someval
> and that is true except for when goint to say
> http://somesite.com/login.php?somevar=someval, in which case that needs to
> be redirected to https://somesite.com/login.php?somevar=someval or similarly
> if it goes to https already, it needs to stay https...

I ignored the query string stuff you had, it's easy enough to add back
in if you meant for it to be significant.

in docroot htaccess:

  RewriteEngine on
  RewriteBase /

  RewriteCond %{HTTPS} =on
  RewriteRule ^(?!login.php$) http://%{HTTP_HOST}%{REQUEST_URI}

  RewriteCond %{HTTPS} !=on
  RewriteRule ^login.php$ https://%{HTTP_HOST}%{REQUEST_URI}

$ wget --no-check-certificate https://localhost/login.phpa.html 2>&1 | grep Loc
Location: http://localhost/login.phpa.html [following]
$ wget --no-check-certificate https://localhost/foo 2>&1 | grep Loc
Location: http://localhost/foo [following]
$ wget --no-check-certificate https://localhost/barlogin.php 2>&1 | grep Loc
Location: http://localhost/barlogin.php [following]
$ wget --no-check-certificate https://localhost/login.php 2>&1 | grep Loc
$

$ wget http://localhost/login.php 2>&1 | grep Loc
Location: https://localhost/login.php [following]
$ wget http://localhost/other.php  2>&1 | grep Loc
$
$ wget http://localhost/otherlogin.php  2>&1 | grep Loc
$
$ wget http://localhost/foo  2>&1 | grep Loc
$

---------------------------------------------------------------------
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] mod_rewrite fails

Posted by James Jones <ja...@freedomnet.co.nz>.
  I've tried dozens of iterations of rules, from simple like ^wp-login 
to much harder and more complex ones matching the whole address or only 
a part of one, it seems that i cant get any of them to work, either the 
rule will rewrite all the urls to http, or i get into an infinite 
redirect loop...

To answer your question that rule rewrites everything, even with 
wp-login in the name to http, seems to completely ignore that whole 
condition

I am not sure that REQUEST_URI always starts with a slash, because if 
you look at the 2.2 docu on apache.org or really anywhere else seems to 
do this just fine, eg (from: 
http://httpd.apache.org/docs/2.2/rewrite/rewrite_flags.html):
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*) index.php?req=$1 [L]

Basically all i am trying to do is to rewrite all the urls going to our 
host, if coming from https to http, except for those going to a 
particular page  (or a set of thereof), and ideally a rule that would 
rewrite http requests for those particular page(s) to https...

example:
everything going to https://somesite.com needs to go to http://somesite.com
so for example https://somesite.com/somedir/somefile.php?somevar=someval 
needs to be redirected to 
http://somesite.com/somedir/somefile.php?somevar=someval
and that is true except for when goint to say 
http://somesite.com/login.php?somevar=someval, in which case that needs 
to be redirected to https://somesite.com/login.php?somevar=someval or 
similarly if it goes to https already, it needs to stay https...

problem seems to be that i can do one, or the other, but cant figure out 
a way to do both at the same time... tried skip conditions, tried 
different regex approaches, it would be easier with a directory...

All of this is in the htaccess context.



Thank you

On 18/10/10 2:00 PM, Eric Covener wrote:
> On Mon, Oct 18, 2010 at 1:43 PM, James Jones<ja...@freedomnet.co.nz>  wrote:
>> can someone explain why neither of these rules work:
> Without a rewritelog or a description of what URL is/is-not rewritten
> as you expect, it will be difficult.
>
> What context are your rules in?  htaccess,<Directory>,<VirtualHost>  ?
>
>> Rule 1:
>> RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(.*)(?!wp-login) [NC]
>> RewriteCond %{HTTPS} on
>> RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]
> Aside from being overly complicated, does this rewrite too much or too little?
>
>>
>> Rule 2:
>> RewriteCond %{REQUEST_URI} ^wp-login(.*)$
> REQUEST_URI always begins with a slash so the rest of this is a no-op.
>
> ---------------------------------------------------------------------
> 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] mod_rewrite fails

Posted by Eric Covener <co...@gmail.com>.
On Mon, Oct 18, 2010 at 1:43 PM, James Jones <ja...@freedomnet.co.nz> wrote:
> can someone explain why neither of these rules work:

Without a rewritelog or a description of what URL is/is-not rewritten
as you expect, it will be difficult.

What context are your rules in?  htaccess, <Directory>, <VirtualHost> ?

> Rule 1:
> RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(.*)(?!wp-login) [NC]
> RewriteCond %{HTTPS} on
> RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L]

Aside from being overly complicated, does this rewrite too much or too little?

>
>
> Rule 2:
> RewriteCond %{REQUEST_URI} ^wp-login(.*)$

REQUEST_URI always begins with a slash so the rest of this is a no-op.

---------------------------------------------------------------------
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