Solved

rewrite rules in apache

Posted on 2014-09-18
8
97 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
  • 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
 

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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
A publishing tool, a Version Control System, or a Collaboration Platform! These can be some of the defining words for the two very famous web-hosting Git repositories: Bitbucket and Github. Git is widely used amongst the programmers and developers f…
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.:
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now