SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Location
    China
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CMS in subdirectory, how to hide it from users?

    I installed my CMS into a subdirectory, because it came out of the box that way. If I had known better, I would have installed it directly into public_html but it's too late now.

    I want to completely hide the subdirectory from users (using .htaccess in public_html), because (a) I don't want anyone to know which CMS I'm using, (b) the CMS has a really dumb name that I want to hide, and (c) it just looks better.

    I know I've done this before with other websites, but I can't find the magical code snippet after searching for over an hour. The best I've found so far has been this:

    Code:
    RewriteCond %{REQUEST_URI} !subdir/
    RewriteRule (.*) http://example.com/subdir/$1 [L]
    This works...halfway. It redirects the front page to /subdir, but any links from the front page have /subdir in them. No good. I want /subdir to disappear completely from all URLs.

    I also tried:
    Code:
    DocumentRoot /subdir
    but I just get 500 internal server error, "/home/username/public_html/.htaccess: DocumentRoot not allowed here"

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,080
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by vellocet View Post
    This works...halfway. It redirects the front page to /subdir, but any links from the front page have /subdir in them. No good. I want /subdir to disappear completely from all URLs.
    This is something you have to do yourself; Apache won't change links in the HTML it sends to browsers. It's probably a setting in your CMS somewhere.

    Anyway, what's the problem with moving directories around so your CMS directory becomes your public_html/ directory? It's a lot simpler and doesn't cause Apache to rewrite all the time. Which doesn't take up a lot of time, but it does take ~some~ time which can be easily avoided if you just move stuff around. You can than 301 redirect everything from subdir/ to / to indicate to SEs that it has moved, and you're all set
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

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

    Rémon is correct and all you will need to do is change the CMS's configuration file (assuming it's WordPress or similar CMS - they all work the same way!). Overall, it's a trivial solution.

    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

  4. #4
    SitePoint Member
    Join Date
    Aug 2011
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #Options +FollowSymLinks
    Options +SymLinksIfOwnerMatch
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(www.)?lilpitt.com$
    RewriteCond %{REQUEST_URI} !^/lilpitt/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /lilpitt/$1
    RewriteCond %{HTTP_HOST} ^(www.)?lilpitt.com$
    RewriteRule ^(/)?$ lilpitt/ [L]



    lilpitt.com is my url n need be replaced... n other "lilpitt" is folder in dir

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

    Is there a question in that? I see several possible problems with your code:

    1. dot characters are not escaped in regex

    2. domain name is not No Case

    3. the first RewriteRule is ANDED with the following RewriteCond (no Last flag)

    4. lots of code but no question.

    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
  •