Solved

apache rewrite problem

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

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 …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

839 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