Tatu Ulmanen
Tatu Ulmanen

Reputation: 124818

What is wrong with this mod_rewrite redirect?

I have a simple redirect which I just can't get to work and I don't know what's wrong. The server's throwing me a 500 Internal Server Error for no reason I can understand.

I'm trying to achieve the following: if a user types the address www.example.com, it will actually be routed to domain/ subdirectory in my server. So if user requests www.example.com/index.htm, it would fetch the file from /var/www/html/domain/index.htm.

Here's what I have so far:

RewriteEngine On
Options +FollowSymlinks

RewriteCond %{SERVER_NAME} =www.example.com
RewriteRule ^(.*)$ domain/$1 [L]

Mod_rewrite is enabled and functional, as this does work:

RewriteRule ^(.*)$ domain/index.php?$1 [L]

What am I missing here?

Upvotes: 0

Views: 118

Answers (1)

Gumbo
Gumbo

Reputation: 655489

You have to exclude the destination you want to redirect to:

RewriteCond %{SERVER_NAME} =www.example.com
RewriteCond $1 !^domain/
RewriteRule ^(.*)$ domain/$1 [L]

Otherwise you will get an infinite recursion since domain/… is also matched by .*.

Upvotes: 3

Related Questions