SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Virtual directory perhaps?

    This is the scenario. I have my website uploaded @ www.example.com/real/ and within that .htaccess directory I have numerous rules to rewrite my URLs. For example I rewrite search.php into a search directory @ www.example.com/real/search

    What I want to do is to make this directory structure completely hidden from the public within my URLs. So if I went to www.example.com/search/ it'd actually be accessing all the info from within the real/search/ directory.

    Is this possible? I don't want to overcomplicate things

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

    Sure! Just add the "real" directory via mod_rewrite.

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^real/
    RewriteRule ^([a-z]+)$ real/$1 [L]
    USE CAUTION in this 'cause any extensionless (LOWERCASE) filename (one or more letters) will get redirected to the real directory!

    Will that do it for you?

    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 Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I put that in my base directory (example.com) and went to example.com/search/ and it didn't work (The requested URL /search/ was not found on this server.)

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

    Ya ditna sae ya wanted to uzz a trailing slash! Specificity, laddie, specificity!
    (Apologies to any Scot reading that!)

    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^real/
    RewriteRule ^([a-z]+)/?$ real/$1 [L]
    ... should take care of your newly discovered trailing slash

    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 Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey again,

    I see how it's working now and fixed it to what I needed Many thanks!

    P.S. Why are you talking in Scottish lol

    Cheers,
    - Dean

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

    Aw, my smart@$$ way of smacking your wrist for adding the trailing slash after you'd had the non-trailing slash answer.

    So long as your problems resolved, IT'S PARTY TIME!

    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

  7. #7
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haha it's all good David Thanks again!

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    No worries, mate!

    Kind of late there, isn't it? Oh, well, I'm normally online late myself. At least you can sleep easy with that problem resolved.

    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

  9. #9
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a further extension question for this. Here is what I have in my .htaccess file currently:
    Code:
    allow from all
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^real/
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]
    I need it to redirect every request at root-level to real except for an index.html file the forum directory and the news directory

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    Oh, my! The expert's back asking questions! We must be in trouble now!

    Using your existing .htaccess to avoid index.html, forum/ and news/:

    Code:
    # allow from all - what's this about?
    
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^(real|forum|news)/?
    RewriteCond %{REQUEST_URI} !^index\.html$
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]
    That should check for the three directories with optional trailing slash, the index.html in root then redirect everything else to the real directory.

    BTW, good work and thanks for all your help in this forum!

    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

  11. #11
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help again David - much appreciated! I'm no expert, just love playing with regexps

    To explain the allow from all, on my localhost in the root htdocs dir I have it set to deny everyone except myself (127.0.0.1) but to over-ride that when I want to show a client something or in this case a preview of my forthcoming site, I put allow from all in a .htaccess file in a subfolder and it allows them to view it, still denying them access to anything else.

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    Thanks for that. I resolve that issue by using the production server in a hidden directory - i.e., not accessible except to those who are provided the URL. I don't allow ANYONE access to my test server 'cause that's my work computer. If you're less fussy than I am, that's a good way to get around the privacy problem.

    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

  13. #13
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whoops I'm back again Unfortunately the rule you gave me above only works for the news directory and the contents of the actual real directory.

    Here is my actual directory structure:

    FolderRoot
    - forum
    - news
    - real
    - .htaccess
    - index.html

    When I go to FolderRoot/forum it should stay there, when I go to FolderRoot/news it should stay there, and the same with index.html. But any other request e.g. FolderRoot/contact/ or FolderRoot/top-rated/ should point to the real dir At the moment it's only working for the news dir + FolderRoot/anything-else/ . The index.html and forum aren't working.

    *sigh* that was hard to explain hehe

    Cheers,
    - Dean

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

    Gee, that should be an all or nothing success story!
    Code:
    allow from all
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^(real|forum|news)/?
    RewriteCond %{REQUEST_URI} !^index\.html$
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]
    If the URL does NOT start with real or forum or news (optional slash) AND the URL is not the root's index.html then "nearly everything" will be redirected to the real directory.

    If this works for real and news (skipping the redirect), that's good. It's inexplicable that it would redirect the index.html and forum, though! You've spelled forum correctly and are not using htm (not html? - drop the "l$" from index\.html$ if you're not sure).

    OUCH! Don't smack me - I really wasn't trying to insult you! Just trying to think of the possible typos that might be messing this up.

    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

  15. #15
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll send you a PM in the morning david to show you this in action, providing that's ok with you of course ? It's just I don't want to post the URL in public

    Edit:


    Hmm, after doing an hours reading through the apache documentation to further expand my knowledge on it I understand exactly how this rewrite works and I have absolutely no idea why your rule doesn't work. It makes no sense eh. I do apologies because the rule does work for the index.html. It just screws up my CSS file location which can be fixed easy enough. So the only problem we have is the forum dir. I have no .htaccess file in the forum directory, it's definately there and as far as I my eyes can see (2.30am in the morning) i'm not typing it incorrectly. I think we have a case of the paranomal here !

    Ok back again, this must be the 4th edit of this post. I made a forum directory within the real directory and the rule is somehow redirecting the request to real/forum. This just makes no sense at all
    Last edited by Dean C; Apr 8, 2005 at 17:31.

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    Hey! Don't you go off and sleep! That's not allowed at 4:10 in the afternoon!

    Okay, if the gremlins are mucking up the works for you, let's tear the offending regex (in the RewriteCond(ition)) apart as if it were three separate conditions:

    Code:
    allow from all
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^real/?
    RewriteCond %{REQUEST_URI} !^forum/?
    RewriteCond %{REQUEST_URI} !^news/?
    RewriteCond %{REQUEST_URI} !^index\.html$
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]
    What do you want to bet that this'll work?

    As for your css file, remember that the redirect makes Apache think that it's in a different directory so you need the HTML base tag in your real scripts (WHAT? You haven't read that seo article I bleat about all the time for this EXACT problem?).



    Thanks for reading up on regex/mod_rewrite so you know that I wasn't leading you astray. We need the experts in here that know what they're doing.

    No problem with the PM with your URL - I understand fully.

    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

  17. #17
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hate to be the bearer of bad news but the forum dir is still pointing to real/forum lol! This makes no sense at all. PM firing your way

  18. #18
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    PM'd back at you to ask whether you tried the "split" version of the RewriteCond. Yeah, the forum didn't work but the news did. Want to try making those R=301 so we can tell where they're going?

    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

  19. #19
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep I did use the split version and just tried with R=301 but I got some crap about redirection limit on the URL. So I changed it back to this:
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^real/?
    RewriteCond %{REQUEST_URI} !^forum/?
    RewriteCond %{REQUEST_URI} !^news/?
    RewriteCond %{REQUEST_URI} !^index\.html$
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]
    And just to prove that the FolderRoot/forum is redirecting to FolderRoot/real/forum I've placed an index.html in the real/forum dir

    P.S. I added a base tag to my index.html and the style and images are still screwed up

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

    You KNOW that those RewriteCond(itions) should work as is but how about trying it without the carat (^) on the forum one? That should be the same thing but would also pickup anything with forum in it (and avoid the redirect).

    Other than playing around with silly things like that, it's got me stumped.

    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

  21. #21
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    WHOA! Something worked 'cause I've got your forum page up now. Did that kill all the others? Was it the carat (or was it misplaced)?

    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

  22. #22
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bingo, I got it
    Code:
    RewriteEngine On
    RewriteCond    %{REQUEST_FILENAME} !-d
    RewriteCond    %{REQUEST_FILENAME} !-s
    RewriteRule ^([0-9A-Za-z-\/\.]+)/?$ real/$1 [L]

  23. #23
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    Aw, that's cheating!

    Gudonya for that one - I didn't even consider checking to see whether it existed as requested.

    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

  24. #24
    SitePoint Wizard Dean C's Avatar
    Join Date
    Mar 2003
    Location
    England, UK
    Posts
    2,906
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe yeah it is kinda cheating but it saves me a bit of hassle. I still am curious to know why the previous rule didn't work. I even tried switching the REQUEST_URI to SCRIPT_FILENAME and misc other things before ending up using the above Ah well

  25. #25
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,692
    Mentioned
    20 Post(s)
    Tagged
    3 Thread(s)
    Dean,

    I just chalk it up to "one of those WinDze things" and ignore it in the hope that it'll go away by morning.

    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
  •