LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   mod_rewrite - rule to change http to https (https://www.linuxquestions.org/questions/linux-server-73/mod_rewrite-rule-to-change-http-to-https-558911/)

Firebar 06-03-2007 06:53 PM

mod_rewrite - rule to change http to https
 
Hi again all,

I've got a directory on my server and I'm trying to make a mod_rewrite rule to say something like;

http://myserver/ssl/

must become

https://myserver/ssl

Any ideas? I'm a bit stumped.

Thanks :)

ABL 06-03-2007 08:06 PM

Quote:

Originally Posted by Firebar
Hi again all,

I've got a directory on my server and I'm trying to make a mod_rewrite rule to say something like;

http://myserver/ssl/

must become

https://myserver/ssl

Any ideas? I'm a bit stumped.

Thanks :)

In your .htaccess file, put the following:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} ssl
RewriteRule ^(.*)$ https://myserver/ssl/$1 [R,L]


That should be it.

--Alden

Firebar 06-04-2007 05:27 AM

Thanks for your reply. Unfortunately that doesn't seem to work for me.

I have the directory stated in /etc/httpd/conf.d/ssl.conf like so;

Code:

<Directory "/var/www/html/ssl">
SSLCipherSuite HIGH:MEDIUM
</Directory>

Do I need to specify it within httpd.conf aswell?

Anyhow, the .htaccess is then in there, but no lucky (apache has been reloaded).

Firebar 06-04-2007 05:40 AM

Can the Rewrite rules be used in the directory statements rather than a .htaccess ?

ABL 06-04-2007 10:51 AM

Quote:

Originally Posted by Firebar
Can the Rewrite rules be used in the directory statements rather than a .htaccess ?

I *believe* you can.

Where did you put the .htaccess? It should be in the ssl folder.

If I get a chance, I'll test this myself, but it's not looking promising.

--Alden

Firebar 06-04-2007 10:55 AM

.htaccess is in the SSL folder. I've got a directory statement in ssl.conf specifying allowoverride all to that .htaccess files are used.

It appears that I can't access it at all now :D hehe

ABL 06-04-2007 11:08 AM

Quote:

Originally Posted by Firebar
.htaccess is in the SSL folder. I've got a directory statement in ssl.conf specifying allowoverride all to that .htaccess files are used.

It appears that I can't access it at all now :D hehe

I am terribly sorry. I did manage to test, and it appears that I've made a mistake with the code I posted.

I will not be able to get to debug any time soon, though. Can someone else on this board help, please?

--Alden

Firebar 06-04-2007 11:35 AM

Thanks for your efforts to help, greatly appreciated.

I'll have a play around in the meantime before a mod_rewrite expert appears ;)

Hangdog42 06-04-2007 12:06 PM

I've used this in a virtual host declaration:

Code:

RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]


Firebar 06-05-2007 06:39 AM

Thanks. Whereabouts should I be putting my directory specification?
Am I doing this completely wrong by specifying it in ssl.conf, although this seems to work..
Would a virtual host declaration be better?

Hangdog42 06-05-2007 07:29 AM

I'm speaking largely out of ignorance here, so take this with a grain of salt.

I would think that ssl.conf wouldn't be the best place to put this. If a connection comes in on http, I'm not sure that ssl ever plays a role, so ssl.conf may not ever be used.

I used a virtual host declaration largely because I have several virtual hosts, and that was the one I wanted re-directed to https no matter what. I suppose .htaccess could do the same, but it was easier to do it in a virtual host declaration since I had to create one anyway.


All times are GMT -5. The time now is 03:33 PM.