Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

apache rewrite problem

Posted on 2013-12-13
3
Medium Priority
?
202 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 2000 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

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.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Loops Section Overview
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

916 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