Forum Moderators: phranque

Message Too Old, No Replies

mod_rewrite crashes the server

problem with mod_rewrite when using it to create subdomains

         

ainars

11:12 am on May 11, 2003 (gmt 0)

10+ Year Member



I have a strange problem with my server. Usally my server's load is under 0.1-0.7. Some time ago I noticed that several times per day server's load grows to 50..70..90... Then it's normal again. Sometimes when this happends I can not access my server anymore and I have to call the data center to restart it manually.

Then I removed .htaccess file what i used to create subdomains. The problem is gone.

I don't know what's wrong with mod_rewrite. Please see my .htaccess file below. Is it OK?

I used mod_rewrite for the following purpose: when an user registers and creates a profile at my site, his/her profile is accessible via:
[domain.com...]

mod_rewrite was used to access user profiles via subdomain: [username.domain.com....]

Most of time it works fine, but sometimes when I try to access some subdomain, nothing loads (I get "page cannot be displayed" error which usually appears when server is down, but my server is not down).

My .htaccess file:
=============
RewriteEngine On
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST}!^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST}!^domain\.com [NC]

RewriteCond %{HTTP_HOST} ^[^.]+\.domain\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^([^.]+)\.domain\.com(.*) go.php?to=myaccount&op=userinfo&uname=$1

RewriteCond %{HTTP_HOST} ^www\.[^.]+\.domain\.com$
RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.([^.]+)\.domain\.com(.*) go.php?to=myaccount&op=userinfo&uname=$1
========

Thanks for your help.
Ainars

jdMorgan

9:16 pm on May 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ainars,

Welcome to WebmasterWorld [webmasterworld.com]!

I see one anomaly and one potential problem:

First, you have two "RewriteEngine on" directives - Delete the first one.

Second, the following regular expression may be a problem for you:

^[^.]+

The "+" requires the group to contain a character, but the group is defined as "^.", which means "not any character." In regular expressions, a "." is a special symbol, and matches any character.

If you wish the group to be defined as "any character except ".", then you must escape the "." with a preceding backslash. The result would be:

^[^\.]+

I don't know if this will correct your problem, but it may help to reveal the actual problem more clearly.

HTH,
Jim

ainars

11:33 pm on May 13, 2003 (gmt 0)

10+ Year Member



Thank you very much for your answer, Jim.

I made your suggested changes and removed one "revrite engine on" directive.

I hope it will fix the problem. Later I will post the results.

Ainars

carfac

8:10 am on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jim:

You may or may not know this, but seems like a good palce to ask...

Do you only need to turn mod_rewrite on once per DOMAIN, or once per DIRECTORY, or once per SERVER?

Say I have 7 Virtual Hosts on my server.... I will need to turn it on 7 times (once for each host), right? Do I need to turn it on in /root/, or how about /root/sub1/ (and then will it only effect there down)?

Thanks!

dave

jdMorgan

12:37 am on May 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From the docs:

"...you need to have a RewriteEngine on directive for each virtual host in which you wish to use it."

Jim

ainars

10:45 pm on May 13, 2003 (gmt 0)

10+ Year Member



it looks that I have another problem. i fixed errors in .htaccess file and 2 days server was working fine. today it crashed again. :(

jdMorgan

12:01 am on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ainars,

You can try this much-simplified version of your code. I think it will accomplish what you need in a much simpler way.

If it does not work, I suggest you locate and hire a local expert to help you debug this problem - someone who can actually stand there and look over your shoulder to see the problem - It sounds like it could be a difficult one.


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !go\.php
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.domain\.com [NC]
RewriteRule .* /go.php?to=myaccount&op=userinfo&uname=%2 [L]

HTH,
Jim

ainars

6:20 pm on May 14, 2003 (gmt 0)

10+ Year Member



Thank you jdMorgan. I will try it.

I noticed one more problem - with wildcarded DNS. In my first post I wrote: "sometimes when I try to access some subdomain, nothing loads (I get "page cannot be displayed)". I just noticed that this happends even if I don't use mod_rewrite.

I have 2 domains, let's say:
domain.lv
domain.lt

One hour ago [anything.domain.lv...] was working fine, but when I tried to access [anything.domain.lt...] - I got "page can not be displayed". I checked httpd.conf file, zone files, but nothing wrong - both domains have similar settings. I restarted DNS services, Apache, but no success - wildcards for domain.lv work fine, but for domain.lt not.

At the same time i was able to access both domains with "www" and without "www".

After some hour both domains started to work fine with addresses like [anyword.domain.lv...] and [anyword.domain.lt....]

It happends every day. I was thinking it's due to mod_rewrite, but now I see that it's another problem. I am getting crazy...

jdMorgan

8:18 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

Sounds like a DNS issue. I'm no expert on that, so I'm afraid I can't help.

I'd recommend posting another question with a new "Help with wild-card DNS" title.

Jim