Hello,

Let me explain the situation first before I will speak about the problem.

We have a website. www.maindomain.com. This domain is the main website of an organisation. The organisation has eight members. Each member has his own page on www.maindomain.com/member1, www.maindomain.com/member2, www.maindomain.com/member3, etc...

www.member1domain.com is dns forwarded to the server of www.maindomain.com. My job is to handle incoming requests from www.member1domain.com and make sure the visitors gets the shown information of the page: www.maindomain.com/member1

i.e. www.maindomain.com/subject1/ gets the information from www.maindomain.com/subject1/.
www.member1domain.com/subject1/ gets the information from www.maindomain.com/member1/subject1/.
When www.member1domain.com/subject1/ does not exists it is forwarded to www.member1domain.com/ (as by request of the customer).
With ErrorDocument 404 /404.php, 404.php redirects user to the root of the requested domain.

The members can all add and edit pages. So urls are added and removed on frequent base.

I have got this code in my .htaccess
RewriteCond %{HTTP_HOST} ^www.maindomain.com$ [NC]
RewriteRule ^([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?$ index.php?arg1=$1&arg2=$2&arg3=$3&arg4=$4&arg5=$5&arg6=$6&arg7=$7&arg8=$8 [NC,L]
RewriteCond %{HTTP_HOST} ^www.member1domain.com$ [NC]
RewriteRule ^([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?([+a-z-_()0-9]+)?/?$ index.php?arg1=member1&arg2=$1&arg3=$2&arg4=$3&arg5=$4&arg6=$5&arg7=$6&arg8=$7 [NC,L]

This works well in rewriting the urls. My PHP script handles the arguments and the right page get shown. But the rules itself in .htaccess are pretty bad I think, because it tries to redirect everything.

Therefore I added the following rule on top of the rewriting rules.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*) - [L]

This makes it a little better, because it stops trying to rewrite files.

However I believe I am totally on the wrong track, because when an outside server tries i.e. to request www.member1domain.com/banners/banner1.jpg and it doesn't exists on te server it starts to try to rewrite it again. And server gets really really slow then. (some external servers were making this request often)
As a solution I created the directory banners and putted rewriteengine off. Website became fast again.

But next time they go looking for images/image.jpg which doesn't exist and it will go slow again. I have to create directory again and put rewriteengine off.


So the way I am heading right now is not the right one.
Can somebody point me into the right direction, so I can come up with a descent solution and rewriting code.

Thanks in advance!