Solved

ReWrite Question

Posted on 2004-08-29
7
375 Views
Last Modified: 2010-03-04
I've been having some trouble setting up a rewrite statement.  

I want any traffic going to http://secure.mydomain.com to be redirected to https://secure.mydomain.com
So I added the following to my httpd.conf

# Virtual hosts
#

# Virtual host Default Virtual Host
<VirtualHost *>
        ServerSignature email
        DirectoryIndex index.php index.html index.htm index.shtml

        RewriteCond   %{SERVER_PORT}  !^443$
        RewriteCond   %{REMOTE_HOST}  ^secure.*
        RewriteRule ^(.*)$ https://secure.mydomain.com/$1 [R]


<IfDefine HAVE_SSL>

</IfDefine>
        LogLevel debug
        HostNameLookups off
</VirtualHost>


Is that a proper Rewrite rule?  Also I put this in http.conf  should it go in ssl.conf?  I've got my virtualhost set up my ssl.conf and it is working fine.  It points mydomain.com/secure to secure.mydomain.com.

##
## SSL Virtual Host Context
##

<VirtualHost _default_:443>

# General setup for the virtual host, inherited from global configuration
DocumentRoot "/var/www/html/secure"
ServerName secure.mydomain.com:443


Thanks,
 --Steven Osborn

Server Info:
Fedora Core 2
Apache 2.0.49
PHP 4.3.4
MySQL 3.23.58
0
Comment
Question by:steve918
  • 4
  • 2
7 Comments
 
LVL 2

Expert Comment

by:brozzis
ID: 11925564

Since such redirection has some sense only on SSL activated, you
could include it in <IfDefine tag...

I added also RewriteEngine On


<VirtualHost *>
        ServerSignature email
        DirectoryIndex index.php index.html index.htm index.shtml

<IfDefine HAVE_SSL>

  RewriteEngine On
        RewriteCond   %{SERVER_PORT}  !^443$
        RewriteCond   %{REMOTE_HOST}  ^secure.*
        RewriteRule ^(.*)$ https://secure.mydomain.com/$1 [R]

</IfDefine>

        LogLevel debug
        HostNameLookups off
</VirtualHost>
0
 
LVL 3

Author Comment

by:steve918
ID: 11928472
No luck.  secure.mydomain.com still just takes me to http://secure.mydomain.com
0
 
LVL 7

Expert Comment

by:CajunBill
ID: 11928802
Try dropping both of the RewriteCond, and change the RewriteRule as follows:

RewriteEngine On
RewriteRule   ^/(.*)   https://secure.mydomain.com/$1   [R]

However, I have not tested this as yet.
And of course we assume that mod_rewrite is built in - but it doesn't hurt to double check it.
And that there are no Rewrite or Alias directives before these Rewrite directives.
0
Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

 
LVL 2

Accepted Solution

by:
brozzis earned 500 total points
ID: 11928811

  RewriteEngine On
        RewriteCond   %{SERVER_PORT}  !^443$
#        RewriteCond   %{REMOTE_HOST}  ^secure.*
        RewriteRule ^(.*)$ https://secure.mydomain.com/$1 [R]

these lines work to me.
Please take a look to the meaning of %{REMOTE_HOST}, it's not the URL requested,
but the requesting address
0
 
LVL 3

Author Comment

by:steve918
ID: 11935625
I tried all the suggestions above, but I'm beggining to think that maybe it isn't my syntax.

I have mod rewrite setup.  It was already loaded on the default Fedora install.
LoadModule rewrite_module modules/mod_rewrite.so

I've tried every possible combination of Rewrite conditions and rewrite rules.  The only thing I'm unsure about is where to put the rewrite statements in the config file.  I've got the secure virtual host setup in the ssl.conf, but i've got the rewrite statements under the default virtualhost in the httpd.conf

0
 
LVL 3

Author Comment

by:steve918
ID: 11945439
OK, I'm getting somewhere.  I added "Options +FollowSymLinks" and I got it working, BUT.  It works all the time now without the second rewrite condition...  Even when I don't want it to.  Like when someone just types www.mydomain.com

 I've got:
      
  RewriteEngine On
        RewriteCond   %{SERVER_PORT}  !^443$
#        RewriteCond   %{REMOTE_HOST}  ^secure.*
        RewriteRule ^(.*)$ https://secure.mydomain.com/$1 [R]

How do I make it only rewrite when someone types in secure.mydomain.com?
0
 
LVL 3

Author Comment

by:steve918
ID: 11946647
It's working now.  I just used the HTTP_HOST variable instead of REMOTE_HOST
0

Featured Post

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question