Solved

rewrite rules in apache

Posted on 2014-09-18
8
93 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
seems to go into a loop like that http://www.mysite.com/mysite/mysite/mysite/mystie/... until it errors out.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:eli2011
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
RewriteEngine On
RewriteCond %{REQUEST_URI} !/mysite/ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/mysite/$1 [R=301,L]

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video teaches users how to migrate an existing Wordpress website to a new domain.

771 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

12 Experts available now in Live!

Get 1:1 Help Now