Forum Moderators: phranque

Message Too Old, No Replies

Problem with mod_rewrite regarding redirecting various domains

         

Oliver Sprenger

7:35 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



Howdy!

Firstly, I am a new member, but this doesn't mean that I didn't have already searched for my problem. As I run a forum myself, I am well aware of the fact that it is annoying to read the same questions again and again. So please excuse me, if this very problem of mine had already been addressed, but I can't seem to find a solution that's already been posted.

I run a website located at http://www.example.org . I own several other domains (~20 of them) that also point to my website, and some 4 or 5 of them are also directly associated with my webspace, while the others are usual redirect.

As cookies only work on the website that issued them, it is necessary to have all these domains consolidated into the main URL http://www.example.org . That's the mod_rewrite rules I am running right now:


RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.org$ [NC]
RewriteRule (.*) http://www.example.org/$1
RewriteBase /cgi-bin/
RewriteRule ^index\.html forum.pl [L]
RewriteRule ^forum([0-9]+)/([0-9]+)\.html$ forum.pl?f=$1&m=$2 [L]
RewriteRule ^forum([0-9]+) forum.pl?f=$1 [L]
RewriteRule ^area([0-9]+) forum.pl?tb=$1 [L]
errorDocument 404 http://www.example.org
errorDocument 403 http://www.example.org

It works absolutely fine, except one thing that annoys me. If one enters http://example.org, he'll get a 500. I really don't know why, because without the rules it works, and even http://example.net gets correctly rewritten. To make myself clearer (I am not an English native speaker), some examples how it should work:

http://www.example.net/forum1/29356.html
http://www.example.org/forum1/29356.html
(and others)

should be rewritten to:

http://www.example.org/forum1/29356.html

what itself gets rewritten to:

http://www.example.org/cgi-bin/forum.pl?f=1&m=29356

The above works perfectly fine. The same is true for

http://example.net/forum1/29356.html
or http://example.net/forum1/29356.html
or even http://example.org/forum1/29356.html

but: if one enters

http://example.org/forum1/29356.html

he gets a 500.

Why is this? I am really totally fed up with this #*$! right now. If would really appreciate anybody pointing me to the right direction.

Thanks, Oliver.

[edited by: jdMorgan at 7:48 pm (utc) on Mar. 12, 2006]
[edit reason] No URLs, please. See Terms of Service. [/edit]

Oliver Sprenger

8:36 pm on Mar 12, 2006 (gmt 0)

10+ Year Member



I am sorry... I must have overlooked the fact, that it isn't allowed to post actual URLs here. However, thru the editing by the moderator the sense of my posting got quite mixed up...

The above works perfectly fine. The same is true for

http://example.net/forum1/29356.html
or [ex-ample.net...]
or even [ex-ample.org...]

Please disregard this paragraph in the original posting.

Oliver Sprenger

8:19 pm on Mar 14, 2006 (gmt 0)

10+ Year Member



Thanks to anybody that might have answered. Solved problem by myself - needed to set R=307 (or 301). Works perfectly now.

jdMorgan

10:56 pm on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



These directives may cause you trouble:

errorDocument 404 http://www.example.org
errorDocument 403 http://www.example.org

The proper form is:

errorDocument 404 /
errorDocument 403 /

If you include the http://<domain> part, then the server will generate a 302-Found response instead of the desired 403 or 404 response. This can lead to massive duplicate-content problems, where your home page URL is replaced in search results with an outdated or forbidden URL.

For best results, each error should be handled with a custom page explaining the error and containing a text link to the home page, and optionally -- a 5-second or greater meta-refresh to the home page.

If you get a 500-Server Error, the first place to look is in your server error log. It will often tell you exactly what is wrong.

Jim