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 Moe <ji...@sohnen-moe.com> on 2011/07/19 00:12:04 UTC

[users@httpd] Simple RewriteRule?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
  apache v2.2

  I have what I thought is a simple re-write rule:

RewriteEngine on
ReWriteRule ^/teachers/(.*)$ https://${HTTP_HOST}/$1 [L,R]

  The idea is that if the teachers page is being loaded, always use the
secure protocol. It does not work.
  Where have I gone wrong?

- -- 
James Moe
moe dot james at sohnen-moe dot com
520.743.3936
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4kr7QACgkQzTcr8Prq0ZPpBQCgoxyZxudAFZk2XX8zcrlDNghi
dhkAn2Vf15qK8Gsn8v3TyBGJ4InbErCd
=aPDO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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] Simple RewriteRule?

Posted by James Moe <ji...@sohnen-moe.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/18/2011 04:37 PM, Geert Mak wrote:
> 
>> I have changed the rule to
>> 
>> RewriteEngine On RewriteCond %{SERVER_PORT} =80 RewriteRule
>> ^/teachers/(.*)$ https://%{HTTP_HOST}/$1 [L,R]
>> 
>> which does not work either. If I change ^/teachers/(.*)$ to ^(.*)$,
>> it works for every page. But I only wanted it to change when
>> entering the teachers page. Clearly, then, I still have the regex
>> wrong. What is the correct way to achieve the redirection?
> 
> What if you move /teachers/ into the RewriteCond?
> 
> RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} /teachers/ 
> RewriteRule ...
> 
  Cool! That worked.

- -- 
James Moe
moe dot james at sohnen-moe dot com
520.743.3936
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4kz7YACgkQzTcr8Prq0ZNJEQCgsbbBqq/f2ZAAi9wpixxxnxaf
TVkAn0+y8dbyaQ+4qwrPRGUgSJF1Bs4O
=CVqk
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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] Simple RewriteRule?

Posted by Geert Mak <po...@verysmall.org>.
>  I have changed the rule to
> 
> RewriteEngine On
> RewriteCond %{SERVER_PORT} =80
> RewriteRule ^/teachers/(.*)$ https://%{HTTP_HOST}/$1 [L,R]
> 
> which does not work either. If I change ^/teachers/(.*)$ to ^(.*)$, it
> works for every page. But I only wanted it to change when entering the
> teachers page.
>  Clearly, then, I still have the regex wrong.
>  What is the correct way to achieve the redirection?

What if you move /teachers/ into the RewriteCond?

Like -

RewriteCond %{SERVER_PORT} 80
RewirteCond %{REQUEST_URI} /teachers/
RewriteRule ...

---------------------------------------------------------------------
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] Simple RewriteRule?

Posted by James Moe <ji...@sohnen-moe.com>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 07/18/2011 03:12 PM, James Moe wrote:
> I have what I thought is a simple re-write rule:
> 
> RewriteEngine on ReWriteRule ^/teachers/(.*)$ https://${HTTP_HOST}/$1
> [L,R]
> 
  I have changed the rule to

RewriteEngine On
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/teachers/(.*)$ https://%{HTTP_HOST}/$1 [L,R]

which does not work either. If I change ^/teachers/(.*)$ to ^(.*)$, it
works for every page. But I only wanted it to change when entering the
teachers page.
  Clearly, then, I still have the regex wrong.
  What is the correct way to achieve the redirection?

- -- 
James Moe
moe dot james at sohnen-moe dot com
520.743.3936
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4kwIEACgkQzTcr8Prq0ZPrMgCgibE2N4RpjWmVbT+Gn5jVaAN4
8dYAn1Rbj5hQesw6SK4VMVFwyA8PEwkg
=XYW3
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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] Simple RewriteRule?

Posted by Igor Cicimov <ic...@gmail.com>.
Typo in ReWriteRule, should be RewriteRule

On Jul 19, 2011 8:12 AM, "James Moe" <ji...@sohnen-moe.com> wrote:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
 apache v2.2

 I have what I thought is a simple re-write rule:

RewriteEngine on
ReWriteRule ^/teachers/(.*)$ https://${HTTP_HOST}/$1 [L,R]

 The idea is that if the teachers page is being loaded, always use the
secure protocol. It does not work.
 Where have I gone wrong?

- --
James Moe
moe dot james at sohnen-moe dot com
520.743.3936
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk4kr7QACgkQzTcr8Prq0ZPpBQCgoxyZxudAFZk2XX8zcrlDNghi
dhkAn2Vf15qK8Gsn8v3TyBGJ4InbErCd
=aPDO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
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] Simple RewriteRule?

Posted by Geert Mak <po...@verysmall.org>.
> Hello,
>  apache v2.2
> 
>  I have what I thought is a simple re-write rule:
> 
> RewriteEngine on
> ReWriteRule ^/teachers/(.*)$ https://${HTTP_HOST}/$1 [L,R]
> 
>  The idea is that if the teachers page is being loaded, always use the
> secure protocol. It does not work.
>  Where have I gone wrong?

I have a working .htaccess which redirects any non-https request over https:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.leicashop.com/$1 [R,L]

In your example I do not see the RewriteCond - you need a condition on which the rule to act, if I am not mistaken.

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