logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: mod_rewrite - http to https
Author
Artesius



Joined: 08 Jun 2006
Posts: 6

PostPosted: Mon 31 Jul '06 16:40    Post subject: mod_rewrite - http to https Reply with quote

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 Wink)
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3049
Location: Hilversum, NL, EU

PostPosted: Mon 31 Jul '06 17:13    Post subject: Reply with quote

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

PostPosted: Mon 31 Jul '06 18:51    Post subject: Reply with quote

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

PostPosted: Tue 01 Aug '06 9:20    Post subject: Reply with quote

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

PostPosted: Tue 01 Aug '06 10:33    Post subject: Reply with quote

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

PostPosted: Tue 01 Aug '06 10:55    Post subject: Reply with quote

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

PostPosted: Tue 01 Aug '06 15:59    Post subject: Reply with quote

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

PostPosted: Tue 01 Aug '06 17:02    Post subject: Reply with quote

I would give a try to your solution.
I've shutdown Apache too many times today, the peoples on the site would be angry Smile

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


Reply to topic   Topic: mod_rewrite - http to https View previous topic :: View next topic
Post new topic   Forum Index -> Apache