LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   apache mod rewrite (https://www.linuxquestions.org/questions/linux-software-2/apache-mod-rewrite-65778/)

Robert0380 06-15-2003 03:33 PM

apache mod rewrite
 
i want to force ssl on certain pages:

like if the request is

http://thepage.com i want to rewrite it so that its https://thepage.com

what would the re-write rule look like for something like that....i dont know how to write the rules.

turnip 06-15-2003 05:46 PM

Code:


RewriteCond %{HTTP_HOST} ^www.domain.net$
rewriteRule ^(.*) https://www.domain.net [L,R=301]

Should work, but it's untested. So let me know.

edit..


Put that in a .htaccess file btw

Robert0380 06-15-2003 08:09 PM

no go, didnt kick out any errors, just didnt work. im reading up on regexes though.


edit.

just saw your edit on .htaccess, gotta try it again.

Robert0380 06-15-2003 08:50 PM

well, which .htaccess file?

the specific site is this (all permutations that i want to change)

http://robert.dynu.net/horde/imp
http://robert.dynu.net/horde
http://robert.dynu.net/horde/imp/login.php


actually i guess you could just say:

http://robert.dynu.net/horde <<<< anything that begins with that

i want to default exactly to :
Code:

https://robert.dynu.net/horde/imp/login.php
which .htaccess file would i put that in?

i want to force secure login to the email system. feel free to check out
the link, you can get horde and imp from http://horde.org

Robert0380 06-16-2003 09:00 PM

.just wanted to bump it up incase someone knew. last time i'll bump this though.

Dayvid 07-31-2003 04:42 PM

I did some googling and found this solution:

Code:

RewriteEngine on
RewriteCond  %{SERVER_PORT}  !^443$
RewriteRule  ^(.*)?$  https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Use that in your .htaccess file. That will rewrite everything in that directory to start with https:// but otherwise remain the same. Works perfectly when I try it, even with in subdirectories etc. without changes. Just put that by itself in your .htaccess file in the dir you want to protect by forcing SSL-only access and then test it.

[edit]I should give credit to this webpage: http://list.cobalt.com/pipermail/cob...er/033818.html for the solution above. The first example shown is what I used, but I modified it first to eliminate the RewriteBase command which I found was not needed (by process of elimination) and I also found that I could use the REQUEST_URI environment variable like I do in CGI scripts to insert whatever document path and name was requested, whereas the original example on that page had you changing the directory. I'd much rather have something that you just drop in and works rather than having to change it depending on what directory you happen to put it in! You may want to try the version on the linked page if mine doesn't work on your hosting provider, since your host may set different environment variables or set them differently than mine (which is http://www.bluevirtual.com).[/edit]


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