We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 51481
    • 45 Posts
    Hi everyone,

    How can I remove /modx/ from all URLs of my website? I kind of screwed up my installation way back when and have been meaning to get to this for a while... My folder tree goes /home/townofco/public_html/modx/index.php so basically I added an extra "modx" folder instead of putting everything directly into public_html. I didn't think this would have any effect but it means that all my urls are www.comox.ca/modx/recreation/ for example.

    It's not a huge deal, but for aesthetic reasons I'd rather not have them there - also, I'd rather any potential hackers not know what CMS I'm using.

    I'm guessing this would be done through the .htaccess file? Here are the contents of the .htaccess file in my public_html folder:
    #RewriteEngine On
    
    #RedirectMatch ^/$ /modx/
    
    RewriteCond %{HTTP_HOST} ^(www\.)?comox\.ca$ [NC]
    RewriteRule !^modx/ /modx%{REQUEST_URI} [L,NC]
    
    # 1 Month for most static assets
    <filesMatch ".(css|jpg|jpeg|png|gif|js|ico)$">
    Header set Cache-Control "max-age=2592000, public"
    </filesMatch>


    And here is the .htaccess file in the modx folder:
    # MODX supports Friendly URLs via this .htaccess file. You must serve web
    # pages via Apache with mod_rewrite to use this functionality, and you must
    # change the file name from ht.access to .htaccess.
    #
    # Make sure RewriteBase points to the directory where you installed MODX.
    # E.g., "/modx" if your installation is in a "modx" subdirectory.
    #
    # You may choose to make your URLs non-case-sensitive by adding a NC directive
    # to your rule: RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]
    
    Options +FollowSymlinks
    RewriteEngine On
    RewriteBase /modx
    
    
    
    # Rewrite www.domain.com -> domain.com -- used with SEO Strict URLs plugin
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com [NC]
    #RewriteRule (.*) http://example-domain-please-change.com/$1 [R=301,L]
    #
    # or for the opposite domain.com -> www.domain.com use the following
    # DO NOT USE BOTH
    #
    #RewriteCond %{HTTP_HOST} .
    #RewriteCond %{HTTP_HOST} !^www\.example-domain-please-change\.com [NC]
    #RewriteRule (.*) http://www.example-domain-please-change.com/$1 [R=301,L]
    
    
    
    # Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent 
    # https://www.domain.com when your cert only allows https://secure.domain.com
    #RewriteCond %{SERVER_PORT} !^443
    #RewriteRule (.*) https://example-domain-please-change.com/$1 [R=301,L]
    
    
    
    # The Friendly URLs part
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    
    
    
    # Make sure .htc files are served with the proper MIME type, which is critical
    # for XP SP2. Un-comment if your host allows htaccess MIME type overrides.
    
    #AddType text/x-component .htc
    
    
    
    # If your server is not already configured as such, the following directive
    # should be uncommented in order to set PHP's register_globals option to OFF.
    # This closes a major security hole that is abused by most XSS (cross-site
    # scripting) attacks. For more information: http://php.net/register_globals
    #
    # To verify that this option has been set to OFF, open the Manager and choose
    # Reports -> System Info and then click the phpinfo() link. Do a Find on Page
    # for "register_globals". The Local Value should be OFF. If the Master Value
    # is OFF then you do not need this directive here.
    #
    # IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
    #
    # Your server does not allow PHP directives to be set via .htaccess. In that
    # case you must make this change in your php.ini file instead. If you are
    # using a commercial web host, contact the administrators for assistance in
    # doing this. Not all servers allow local php.ini files, and they should
    # include all PHP configurations (not just this one), or you will effectively
    # reset everything to PHP defaults. Consult www.php.net for more detailed
    # information about setting PHP directives.
    
    #php_flag register_globals Off
    
    
    
    # For servers that support output compression, you should pick up a bit of
    # speed by un-commenting the following lines.
    
    #php_flag zlib.output_compression On
    #php_value zlib.output_compression_level 5
    
    
    
    # The following directives stop screen flicker in IE on CSS rollovers. If
    # needed, un-comment the following rules. When they're in place, you may have
    # to do a force-refresh in order to see changes in your designs.
    
    #ExpiresActive On
    #ExpiresByType image/gif A2592000
    #ExpiresByType image/jpeg A2592000
    #ExpiresByType image/png A2592000
    #BrowserMatch "MSIE" brokenvary=1
    #BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
    #BrowserMatch "Opera" !brokenvary
    #SetEnvIf brokenvary 1 force-no-vary
    
    # Expires Headers
    <IfModule mod_expires.c>
    # Enable expirations
    ExpiresActive On 
    # Default directive
    ExpiresDefault "access plus 1 month"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year"
    # Images
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    # CSS
    ExpiresByType text/css "access plus 1 month"
    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
    </IfModule>


    Many thanks!

    Oh, almost forgot - the website is http://comox.ca/modx/index.php if that helps!
      • 42562
      • 1,145 Posts
        TinymceWrapper: Complete back/frontend content solution.
        Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
        5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
        • 51481
        • 45 Posts
        Quote from: donshakespeare at Jul 24, 2018, 06:07 PM
        Is this helpful?
        https://stackoverflow.com/questions/2402140/use-a-subdirectory-as-root-with-htaccess-in-apache-1-3

        Hmmm, that looks like it might be the ticket! I'll give it a shot later and post back with results.

        Thanks for the quick reply!
          • 51481
          • 45 Posts
          As per the instruction in that stackoverflow, I changed my .htaccess file in the public_html/ folder to the following:

          RewriteEngine On
          
          # Map http://www.comox.ca to /modx.
          RewriteRule ^$ /modx/ [L]
          
          # Map http://www.comox.ca/x to /modx/x unless there is a x in the web root.
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_URI} !^/modx/
          RewriteRule ^(.*)$ /modx/$1
          
          # Add trailing slash to directories within modx
          # This does not expose the internal URL.
          RewriteCond %{SCRIPT_FILENAME} -d
          RewriteRule ^modx/(.*[^/])$ http://www.comox.ca/$1/ [R=301]


          Buuuut nothing seems to have changed. If I type in comox.ca/recreation it goes to the right page, but the URL shows comox.ca/modx/recreation/

          Any ideas? All this RewriteRule stuff is sorcery to me...
            • 46886
            • 1,154 Posts
            Yes it is sorcery, totally understand and agree

            The problem is you are doing it twice


            # Map http://www.comox.ca to /modx.
            RewriteRule ^$ /modx/ [L]


            its done

            Friendly part has *no* /modx/ folder involved

            This is just a guess, ymmv, but this bit of spell does work, verified

            # The Friendly URLs part
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
            RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
            RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
            RewriteRule ^(.*)$ index.php?q=$1 [L,QSA,NC]


            and, if there are further problems, I suggest

            RewriteRule ^$ /modx/ [L]


            As the misaligned bit

            Oh I also notice your original code, which I think I can see the problem. Keep in mind I am no expert

            RewriteCond %{HTTP_HOST} ^(www\.)?comox\.ca$ [NC]
            RewriteRule !^modx/ /modx%{REQUEST_URI} [L,NC]


            What you've actually done here is re-written /modx/ folders to /modx folder. I could be totally off base here tho, go with the verified stuff first [ed. note: nuan88 last edited this post 5 years, 9 months ago.]