Solved

ReWrite Question

Posted on 2004-08-29
7
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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). #…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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