Solved

rewrite rules in apache

Posted on 2014-09-18
8
105 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

726 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