SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Location
    Budapest, Hungary, Hungary
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mod_rewrite: checking id file exists not working

    Hi folks,

    I'm trying using the following rule without success and nobody could help me so far:

    Code:
    RewriteCond %{DOCUMENT_ROOT}/apps/%{HTTP_HOST}/$1 -f
    RewriteCond %{DOCUMENT_ROOT}/apps/%{HTTP_HOST}/$1 -d
    RewriteRule ^(.*)$ /apps/%{HTTP_HOST}/$1 [L]
    My folder structure is: /apps/[DOMAIN.COM]/ that's why i need %{HTTP_HOST} there.
    Example file: domain.com/apps/domain.com/file.jpg
    Want to reach this as: domain.com/file.jpg but it seems like it's jumping over the rule but the file exists...

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

    I understand your code but believe that Domain.com's DocumentRoot should be what you've labeled %{DocumentRoot}/apps/%{HTTP_HOST} so all your code should be skipped (not matched). If you've created your domain.com correctly, it should be to the (physical address of the) %{DocumentRoot}/apps/%{HTTP_HOST} directory.

    But that's only the first problem. These RewriteCond tests are ANDed so, to match both, the request must be to both a file and a directory!

    Finally, the EVERYTHING atom you've used in the RewriteRule will match everything (and NOTHING) and will cause the block to loop.

    You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It's helped may members and should help you, too.

    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 Member
    Join Date
    Jan 2013
    Location
    Budapest, Hungary, Hungary
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, %{DocumentRoot} is /
    There is my index.php too. I've did my framework to be able to handle multiple sites/domains in one instace. The /apps/%{HTTP_HOST} only holds controllers, views, and assets. Now my URL are look like this for example a CSS file:
    http://domain.com/apps/domain.com/assets/style.css but i want to make like this http://domain.com/assets/style.css
    I'm can't write rules for css/subfolders/images/etc. cuz i'm giving my clients/project members access the /apps/domain.com folder only where they can do anything they want. That's why i want to have a universal code for these things.

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

    I believe you've defined an impossible problem because:

    1. The server's root is the httpd's root, too?
    2. You want to use domain.com for your .htaccess. Just how many "domain.com"s do you have? Is there a domain.com for every {HTTP_HOST} (there must be so your single use - across many clients - is impossible). Are you aware that domain.com IS the {HTTP_HOST}?
    3. You only want to give access to apps/%{HTTP_HOST} to your {HTTP_HOST} client. Does this really mean that they don't have access to domain.com's root?
    4. Apparently, assuming the above to be incorrect, you've apparently not tested the changes to your mod_rewrite code as recommended above - I'm not sure how to get out of the loop you've defined in the RewriteRule, though.


    Think out of the box! Develop offline in a test server then upload the test to a subdirectory of the actual server for the client to check (assuming they can't view your test server in action). With a test server, you can create all the virtual host domains you need (I do this and either drop the TLD or use an acronym for a domain) making testing as close as possible to the real server.

    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

  5. #5
    SitePoint Member
    Join Date
    Jan 2013
    Location
    Budapest, Hungary, Hungary
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the effort, but i already did it.

    Code:
    RewriteCond %{DOCUMENT_ROOT}/apps/%{HTTP_HOST}/$1 -f
    RewriteRule ^(.*)$ /apps/%{HTTP_HOST}/$1 [L]
    
    RewriteCond %{DOCUMENT_ROOT}/apps/%{HTTP_HOST}/$1 -d
    RewriteRule ^(.*)$ /apps/%{HTTP_HOST}/$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    Yeah, i could use [OR] statement in one block instead of two for the first 2 but it was throwing 500, dont know why. But this solution is working just great.

    No, %{DOCUMENT_ROOT} is not my server root, that was a misunderstanding by my fault. But it's the root for my PHP Framework.

    apps
    domain.com
    domain2.com
    domain3.com
    system
    index.php

    That's why i was needed that rule, so i can server directly from those subfolders just like in a normal virtual host

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

    Ah, a specificity problem! Isn't that always the way?

    Okay, I'm glad that you've gotten it working for youself. I still don't follow the use of %{HTTP_HOST} when domain.com is always your {HTTP_HOST} (and you're looking to match domain.com, domain2.com and domain3.com. I fear that you'll still have problems with this unless you specify your values for each place where you're using %{HTTP_HOST}.

    Hmmm, have you defined all three domains with the same ServerPath? If that's the case, you may have found a way to beat the system!

    As for your 500 errors, I'd guess that you used the [OR] flag after both RewriteCond statements (the second one is the error).

    By definition, {DOCUMENT_ROOT} is the physical path to the DocumentRoot of a domain, in this case, your domain.com.

    Back to your original question, though: I don't believe that you can hide the URI ... but the new information may have changed that - especially if the three domains are actually colocated - and you would do it exactly the way that you have the code now.



    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


Tags for this Thread

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
  •