SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with rewriting urls, website becomes slow

    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!

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    van,

    I'm not sure how the member domains get resolved to the maindomain but I'll assume that's properly handled AND the memberdomain is recognized as an {HTTP_HOST} string. If that's the case (the memberdomains are parked on maindomain), I'd recommend that they be removed as "parked" domains and added as "Addon" domains with each pointing to its own subdirectory of maindomain. Doing that would protect each member from having his/her code altered by the other members and resolve your problem at the same time.

    No? Argh!

    Then, assuming that the memberdomains are contained in the {HTTP_HOST], simply check for each memberdomain and redirect to the correct subdirectory (after checking that the request wasn't already made to the subdirectory, of course). When you do that, you don't need to worry about parsing the {REQUEST_URI} as you simply pass it as to the redirection following the subdirectory.

    Problem? It looks like you're using a single CMS (index.php with an horrid query string). If you REALLY need to do that, then you're shooting yourself in the foot with your redirections to the subdirectories (around the index.php handler for the CMS).

    In other words, it may be better for you to rethink your website structure OR use a better manner of segregating member content.



    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2008
    Location
    The Netherlands
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi dklynn,

    Thank you for your answer.

    I actually do not know how the domains are added. The hosting of the website is not in my hands. I had asked if it they could point them to an subdirectory of the main organisations root. For some reason this was not possible. I might pursuade them a bit more. But I do know all domains are recognized in {HTTP_HOST} string.

    But I have one question if the members get their own subdirectory. Say rootmaindomain/images has images that have to be requested by all members, can they reach them with www.member1domain.com/images or should there be some virtuallinks or symlinks

    This website was a bit of a hurry due to holidays and people making deadlines which are impossible to comply to.

    The CMS has indeed some flaws, but I am working on it (it's old CMS, which I am redeveloping at the moment). I guess they query string and redirection has just gotten very high priority. The index.php

    I think I got some usefull tips and will try to follow your advise.

    Thank you very much.

    Regards,

    RvanD85

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    van,

    They're not making it easy on you, are they? Oh, well, I thought I should point that out as that could solve nearly all your problems right out of the box!

    If the domains are all recognized, then that's the equivalent of cPanel's "parked." All you'll need to do is create a "map" of these "member domains" in the {HTTP_HOST} string and redirect to the appropriate subdirectory (or value in a query string).

    In the "Addon solution," the maindomain's images directory would be OUTSIDE the webspace of the memberdomains but its images can always be linked externally (if you're using any sort of image protection, be sure to allow them).

    Old CMS? If it's an internal project, be wary of security issues. If a public CMS, be sure you have the latest updates as they are almost always to close major security holes!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •