Solved

rewrite rules in apache

Posted on 2014-09-18
8
106 Views
Last Modified: 2014-11-17
hi
i have this rewrite rule in place on my apache server

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

i'm trying to get all requests to go to http://www.mysite.com/mysite/
when i type mysite.com on my browser it forwards/rewrites correctly but when i try it with www.mysite.com it doesn't redirect.  would this be the rewritecond or something else like dns?
thanks
0
Comment
Question by:eli2011
[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
  • 4
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40331871
Try

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

Open in new window

0
 

Author Comment

by:eli2011
ID: 40331893
it adds an extra / at the end when i try it that way.  so when i type mysite.com i get to http://www.mysite.com/mysite//
 but when i type www.mysite.com it still returns a "not found"
0
 
LVL 58

Expert Comment

by:Gary
ID: 40332773
RewriteEngine On
RewriteCond %{HTTP_HOST} mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/mysite$1 [R=301,L]

Open in new window

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:eli2011
ID: 40333571
seems to go into a loop like that http://www.mysite.com/mysite/mysite/mysite/mystie/... until it errors out.
0
 

Author Comment

by:eli2011
ID: 40333575
modified the document root and get this now


Forbidden
you don't have permission to access / on this server.  
not sure if this is on a better track to fixing the problem.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40333576
Obviously d'oh

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

Open in new window

0
 

Author Comment

by:eli2011
ID: 40333688
that puts it in a loop too.
if i edit it like this it gives me a "Forbidden"  " you don't have permission to access / on this server"
could it be something else at this point?
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com$ [OR]
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/mysite$1 [R=301,L]
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 40333750
RewriteEngine On
RewriteCond %{REQUEST_URI} !/mysite/ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/mysite/$1 [R=301,L]

Open in new window

0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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