[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ReWrite Question

Posted on 2004-08-29
7
Medium Priority
?
379 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Accepted Solution

by:
brozzis earned 1000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

656 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