?
Solved

rewrite rules in apache

Posted on 2014-09-18
8
Medium Priority
?
107 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
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

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 2000 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

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

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.:
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…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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