Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Problem with rewrite rule |
|
Author |
|
mhashemi
Joined: 09 Mar 2011 Posts: 4
|
Posted: Wed 09 Mar '11 6:23 Post subject: Problem with rewrite rule |
|
|
Let me start off by saying that I'm quite new to Apache. I've just installed it for the first time on Windows Server 2008R2 and I'm trying to modify the httpd.conf file to redirect all myCompany.com to www.myCompany.com for our internal clients (since the Windows Server provides DNS internally, but not externally).
My httpd.conf is below. When I got to localhost or myCompany.com, all I get is index.html. Someone suggested meta refresh, but I'd prefer a 301. What am I doing wrong? Thanks.
Admin note:
Forum rules says: - Do not paste whole configuration files (php.ini, httpd.conf etc.) and dumps, paste only the relevant parts or use a pastbin, for example http://apache.pastebin.ca/ .
This Forum is not a consulting service where you can dump your config file and ask for it to be analyzed. It is a forum where you can ask specific questions and include small, relevant config excerpts.
|
|
Back to top |
|
mhashemi
Joined: 09 Mar 2011 Posts: 4
|
Posted: Wed 09 Mar '11 15:33 Post subject: |
|
|
I should add that I'm running 2.2.17. |
|
Back to top |
|
mhashemi
Joined: 09 Mar 2011 Posts: 4
|
Posted: Wed 09 Mar '11 20:11 Post subject: |
|
|
Since I don't know much about Apache, I'm not sure what parts of the httpd.conf file is relevant and which isn't. I guess I'll post this part:
RewriteCond %{HTTP_HOST} !^www\.myDomain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.myDomain.com/$1 [L,R]
Is that better? |
|
Back to top |
|
Brian White
Joined: 24 Aug 2008 Posts: 21
|
|
Back to top |
|
mhashemi
Joined: 09 Mar 2011 Posts: 4
|
Posted: Thu 10 Mar '11 16:34 Post subject: |
|
|
I'm sorry I didn't read the entire Internet about Apache. For others who might be looking, my conf file snippet is below.
@Brian White: I'd seen the rewrite guide, that's how I came to use my previously posted lines.
A helpful person noted that adding the following might help:
Code: |
Options +FollowSymLinks
RewriteEngine On
|
So, the final five lines of my functional httpd.conf are:
Code: |
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.myDomain\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.myDomain.com/$1 [L,R,NE]
|
|
|
Back to top |
|
James Blond Moderator

Joined: 19 Jan 2006 Posts: 7407 Location: EU, Germany, Next to Hamburg
|
Posted: Fri 11 Mar '11 5:29 Post subject: |
|
|
For a 301 you should use
Code: |
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
|
|
|
Back to top |
|
|
|
|
|
|