logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

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.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Problem with rewrite rule
Author
mhashemi



Joined: 09 Mar 2011
Posts: 4

PostPosted: Wed 09 Mar '11 6:23    Post subject: Problem with rewrite rule Reply with quote

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

PostPosted: Wed 09 Mar '11 15:33    Post subject: Reply with quote

I should add that I'm running 2.2.17.
Back to top
mhashemi



Joined: 09 Mar 2011
Posts: 4

PostPosted: Wed 09 Mar '11 20:11    Post subject: Reply with quote

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

PostPosted: Thu 10 Mar '11 4:59    Post subject: Reply with quote

I generally don't like to say RTFM but canonical hostnames is the second example in the URL Rewriting Guide at apache.org. Please read http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html and post again if you still have any questions.
Back to top
mhashemi



Joined: 09 Mar 2011
Posts: 4

PostPosted: Thu 10 Mar '11 16:34    Post subject: Reply with quote

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

PostPosted: Fri 11 Mar '11 5:29    Post subject: Reply with quote

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


Reply to topic   Topic: Problem with rewrite rule View previous topic :: View next topic
Post new topic   Forum Index -> Apache