Solved

apache rewrite problem

Posted on 2013-12-13
3
195 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 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39718257
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
ID: 39718356
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
ID: 39798449
Had hoped for follow-up but this solution works and that's the bottom line.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

19 Experts available now in Live!

Get 1:1 Help Now