Solved

apache rewrite problem

Posted on 2013-12-13
3
193 Views
Last Modified: 2014-01-21
One of the secondary domains I host on my ubuntu demo server has this to ensure that the url starts with www:

RewriteCond %{HTTP_HOST} !^www.mydomain.com [NC]
RewriteRule (.*)   http://www.mydomain.com$1 [L,R=301]

Open in new window


That works for this domain and all the others.  But for this domain I would also like to redirect users to a subdirectory under the domain's doc root. I tried this:

 #RewriteCond %{REQUEST_URI}  !/myfolder
 #RewriteRule  .*    /myfolder%{REQUEST_URI}    [L]

Open in new window


but then other secondary domains on my server are redirected to this one. I'm not sure how to fix this, nothing I've tried works. I would prefer to use a single ruleset for these two objectives if that's possible.

TIA
0
Comment
Question by:sara_bellum
  • 2
3 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
Comment Utility
Try adding an additional condition to the second set:

RewriteCond %{HTTP_HOST} ^www.mydomain.com [NC]
RewriteCond %{REQUEST_URI}  !/myfolder
RewriteRule  .*    /myfolder%{REQUEST_URI}    [L]

Open in new window


...and put it below the other rules.
0
 

Author Comment

by:sara_bellum
Comment Utility
Perfect, thanks very much! So it's a 2-step process, but it makes sense so that's fine with me.

I'm confused about when to use HTTP_HOST and when to use REQUEST_URI when defining conditions and rewrite rules.  If you can give me a few rules of thumb on how they work it would help, thanks!
0
 

Author Closing Comment

by:sara_bellum
Comment Utility
Had hoped for follow-up but this solution works and that's the bottom line.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Website being blocked? 3 114
Virtual host in apache 31 73
how to use external config file with Spring MVC 4 59
.htaccess file settings 4 31
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now