LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 06-03-2007, 06:53 PM   #1
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Rep: Reputation: 15
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
 
Old 06-03-2007, 08:06 PM   #2
ABL
Member
 
Registered: Mar 2005
Location: NYC
Distribution: CentOS 5
Posts: 54

Rep: Reputation: 16
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
 
Old 06-04-2007, 05:27 AM   #3
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Original Poster
Rep: Reputation: 15
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).

Last edited by Firebar; 06-04-2007 at 05:38 AM.
 
Old 06-04-2007, 05:40 AM   #4
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Original Poster
Rep: Reputation: 15
Can the Rewrite rules be used in the directory statements rather than a .htaccess ?
 
Old 06-04-2007, 10:51 AM   #5
ABL
Member
 
Registered: Mar 2005
Location: NYC
Distribution: CentOS 5
Posts: 54

Rep: Reputation: 16
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
 
Old 06-04-2007, 10:55 AM   #6
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Original Poster
Rep: Reputation: 15
.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 hehe
 
Old 06-04-2007, 11:08 AM   #7
ABL
Member
 
Registered: Mar 2005
Location: NYC
Distribution: CentOS 5
Posts: 54

Rep: Reputation: 16
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 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
 
Old 06-04-2007, 11:35 AM   #8
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Original Poster
Rep: Reputation: 15
Thanks for your efforts to help, greatly appreciated.

I'll have a play around in the meantime before a mod_rewrite expert appears
 
Old 06-04-2007, 12:06 PM   #9
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,790
Blog Entries: 1

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
I've used this in a virtual host declaration:

Code:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://%{SERVER_NAME}/$1 [R,L]
 
Old 06-05-2007, 06:39 AM   #10
Firebar
Member
 
Registered: Feb 2005
Location: Southampton (UK)
Distribution: Debian, RHEL and SuSE
Posts: 69

Original Poster
Rep: Reputation: 15
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?
 
Old 06-05-2007, 07:29 AM   #11
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,790
Blog Entries: 1

Rep: Reputation: 414Reputation: 414Reputation: 414Reputation: 414Reputation: 414
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_rewrite rule question jmoschetti45 Linux - Software 0 03-19-2007 07:29 PM
http and https wennie Linux - Software 1 04-01-2005 11:47 AM
mod_rewrite *and* http authentication belorion Linux - General 0 01-20-2005 04:05 PM
HTTP to HTTPS shegde Linux - Software 8 01-31-2003 04:29 AM
https or http? antken Programming 3 10-30-2002 05:06 PM


All times are GMT -5. The time now is 03:58 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration