Author |
|
Artesius
Joined: 08 Jun 2006 Posts: 6
|
Posted: Mon 31 Jul '06 16:40 Post subject: mod_rewrite - http to https |
|
|
Hello !
I want to activate the SSL protocol on 2 pages of my website.
It's a bit special because my URL is like that:
http://www.domain.tld/?page=blob
It seems that Apache couldn't handle the query string.
I've tried this
Code: |
RewriteCond %{QUERY_STRING} ^/\?page=blob$
RewriteRule https://%{SERVER_NAME}%{QUERY_STRING} [R,L]
|
But the protocol didn't change.
If you have any idea (or correction ) |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3092 Location: Hilversum, NL, EU
|
Posted: Mon 31 Jul '06 17:13 Post subject: |
|
|
Im am not a rewrite guru, did you tried ?
RewriteCond %{QUERY_STRING} ^/\?page=blob$
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
or
RewriteCond %{QUERY_STRING} ^/\?page=blob$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [R,L]
Steffen |
|
Back to top |
|
Jorge
Joined: 12 Mar 2006 Posts: 376 Location: Belgium
|
Posted: Mon 31 Jul '06 18:51 Post subject: |
|
|
Code: | RewriteEngine On
RewriteCond %{QUERY_STRING} ^/\?page=blob$
RewriteRule .* https://%{HTTP_HOST}:443%{REQUEST_URI} [QSA,R=permanent,L] |
Try that |
|
Back to top |
|
Artesius
Joined: 08 Jun 2006 Posts: 6
|
Posted: Tue 01 Aug '06 9:20 Post subject: |
|
|
Thanks
Sadly both didn't work.
The aim is that nobody could access to this page without being in SSL... |
|
Back to top |
|
pnllan
Joined: 05 Dec 2005 Posts: 221
|
Posted: Tue 01 Aug '06 10:33 Post subject: |
|
|
Please post relative CONF info - not the whole thing just pertaint directives - neuter for security sake. |
|
Back to top |
|
Artesius
Joined: 08 Jun 2006 Posts: 6
|
Posted: Tue 01 Aug '06 10:55 Post subject: |
|
|
Code: |
<VirtualHost xxx.xxx.xxx.xxx>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "xxxxxxxxx"
ServerName xxx.xxx.xxx.xxx
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=formulaire_etat_civil$
RewriteRule ^$ https://%{HTTP_HOST} [QSA,L]
</VirtualHost>
#General rule
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
#Special rule for the directory
Alias "/Acc" "xxxxxxxxxxxxxxxxx"
<Directory "xxxxxxxxxxxxxxxxxxx">
Options Indexes FollowSymLinks Includes
AllowOverride All
Allow from all
</Directory>
|
Actually i'm testing on my PC before switching to the production server.
The rules are basically the same. |
|
Back to top |
|
pnllan
Joined: 05 Dec 2005 Posts: 221
|
Posted: Tue 01 Aug '06 15:59 Post subject: |
|
|
I'm presuming that directory for the Alias is the same as the directory for the Directory directive....trying saying the real fast.
Wouldn't your rewrite directives be better suited to your 'special' directory rather than for the Virtual Host? Such as:
Code: | <VirtualHost xxx.xxx.xxx.xxx>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "xxxxxxxxx"
ServerName xxx.xxx.xxx.xxx
</VirtualHost>
#Special rule for the directory
Alias "/Acc" "xxxxxxxxxxxxxxxxx"
<Directory "xxxxxxxxxxxxxxxxxxx">
Options Indexes FollowSymLinks Includes
AllowOverride All
Allow from all
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=formulaire_etat_civil$
RewriteRule ^$ https://%{HTTP_HOST} [QSA,L]
</Directory> |
Context on the Mod_Rewrite directives you are using include: server config, virtual host, directory, .htaccess. |
|
Back to top |
|
Artesius
Joined: 08 Jun 2006 Posts: 6
|
Posted: Tue 01 Aug '06 17:02 Post subject: |
|
|
I would give a try to your solution.
I've shutdown Apache too many times today, the peoples on the site would be angry
For the moment i've put a php snippet to do the same thing...
This one in my main index.
Code: |
if(($_SERVER['HTTPS']=='on') && ($_GET['page']!='formulaire_etat_civil') && ($_GET['page']!='formulaires_envoi'))
{
($_SERVER['QUERY_STRING']!='') ? $query_string_ssl='?'.$_SERVER['QUERY_STRING'] : $query_string_ssl='';
header('Location: http://'.$_SERVER['HTTP_HOST'].'/'.$query_string_ssl);
}
|
And this one to the secured page.
Code: |
if($_SERVER['HTTPS']=='') header('Location: https://'.$_SERVER['HTTP_HOST'].'/?page='.$_GET['page']);
|
|
|
Back to top |
|