We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50485
    • 56 Posts
    Hi
    Wonder if anyone can advise me how to get Friendly URLS working. I have followed the instructions at https://docs.modx.com/revolution/2.x/administering-your-site/using-friendly-urls but think the location of my .htaccess file may the problem and not knowing about re-writes I do not know what to do.

    My modx install in is in a direction called public_html
    As per the instructions on installation I moved the .htaccess file to a sub-folder called core.
    I still have the ht.access file at the root of the MODX install.

    The contents of both files are below - any chance someone could tell me what I need to alter to not get a 404 error message - Much appreciated.

    .htaccess file contents:

    IndexIgnore */*
    <Files *>
    Order Deny,Allow
    Deny from all
    </Files>
    # 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]

    RewriteEngine On
    RewriteBase /


    # 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

    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # Adaptive-Images -----------------------------------------------------------------------------------

    # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
    # RewriteCond %{REQUEST_URI} !some-directory
    # RewriteCond %{REQUEST_URI} !another-directory

    RewriteCond %{REQUEST_URI} !assets

    # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
    # to adaptive-images.php so we can select appropriately sized versions
    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

    # END Adaptive-Images -------------------------------------------------------------------------------
    </IfModule>






    ht.access file contents:

    # deny access to _all_ files in the core, including changelog.txt and error.log
    # original borrowed from owncloud
    
    # line below if for Apache 2.4
    <ifModule mod_authz_core.c>
        Require all denied
    </ifModule>


    # line below if for Apache 2.2
    <ifModule !mod_authz_core.c>
    deny from all
    Satisfy All
    </ifModule>

    # section for Apache 2.2 and 2.4
    IndexIgnore *

    This question has been answered by missusdoubleyou. See the first response.

      • 36582
      • 463 Posts
      You should have that main .htaccess file in the root of your site and another .htaccess file in your core folder with contents something like...

      IndexIgnore */*
      <Files *>
          Order Deny,Allow
          Deny from all
      </Files>


      BUT you should also remove those 5 lines of code from the top of your .htaccess file. Obviously you're not telling us much about your set up so I can only speak in terms of the way I have things set up.
        Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk
        • 50485
        • 56 Posts
        Hi Chrisandy

        If i copy the .htaccess file in core to public - keeping indexignore... in the core folder but all else in the .htaccess copy in public_html I now get a 403 error and cant even get back into MODX.

        I get this message

        If you are the webmaster of this site please log in to Cpanel and check the Error Logs. You will find the exact reason for this error there.
        
        Common reasons for this error are:
        
        Incorrect file/directory permissions: Below 644.
        In order files to be read by the webserver, their permissions have to be equal or above 644. You can update file permissions with a FTP client or through cPanel's File Manager.
        
        Restrictive Apache directives inside .htaccess file.
        There are two Apache directives which can cause this error - 'Deny from' and 'Options -Indexes'.


        I also dont understand because when you get a set up of MODX, it says move the .htaccess file from the root directory?

        Sorry to be so confused and incompetent! Advice most welcome.
          • 50485
          • 56 Posts
          To give some more info

          The MODX tutorial says:

          The .htaccess file can be anywhere above the MODX installation but the usual location is in the MODX site root (along with the ht.access file, and the assets, manager and connectors directories). You can also put the file in /htdocs or /public_html or what ever your server uses as long as it is in, or above, the MODX root directory.

          However, when I try copy it to the public_html directory I then cant access MODX or the site - I get a 500 error message - "internal server error". Can anyone advise about this?

          Su
            • 3749
            • 24,544 Posts
            Does it work if you put it in the MODX site root?
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 50485
              • 56 Posts
              Hi Bob

              When I tried to move the .htaccess file into the public_html directory I was locked out of the MODX manager getting a 403 message. My hosting company have created a .htaccess file there but whilst I can get back into the MODX manager I am still seeing a 403 message when i try and view any pages on the site now that I have friendly URLs enabled.
                • 3749
                • 24,544 Posts
                Is public_html the MODX site root (containing the assets, manager, and connectors directories)?

                Make sure you have this tag in the head section of all MODX templates:

                <base href="[[!++site_url]]" />

                  Did I help you? Buy me a beer
                  Get my Book: MODX:The Official Guide
                  MODX info for everyone: http://bobsguides.com/modx.html
                  My MODX Extras
                  Bob's Guides is now hosted at A2 MODX Hosting
                  • 3749
                  • 24,544 Posts
                  Is it possible that you've copied the wrong .htaccess file to the root?

                  It should be the same as the ht.access file in the MODX root. You can either rename that, or (better), create a new file called .htaccess and paste the content of ht.access into it.

                  Also, see my post just above.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 50485
                    • 56 Posts
                    Hi Bob

                    <base href="[[!++site_url]]" /> - Got that!
                    Yes, I now have a .htaccess file in the root (my hosting provider created one there). Public_html is where all the other modx folders like assets are sitting. BUT they have left the .htaccess file I originally moved from root to the Core folder. This means I now have two .htaccess files (one in Core the other in root) and one ht.access file in root.

                    The two .htaccess files have different contents - and neither replicate the ht.access file. I have copied them all below.

                    Any further advice is much appreciated as whilst I can see my holding page ok, whenever I try and view the site via the MODX manager I get this error message:

                    _____

                    403 - Forbidden Error
                    You are not allowed to access this address.
                    If the error persists, please contact the website webmaster.
                    If you are the webmaster of this site please log in to Cpanel and check the Error Logs. You will find the exact reason for this error there.

                    Common reasons for this error are:

                    Incorrect file/directory permissions: Below 644.
                    In order files to be read by the webserver, their permissions have to be equal or above 644. You can update file permissions with a FTP client or through cPanel's File Manager.


                    Restrictive Apache directives inside .htaccess file.
                    There are two Apache directives which can cause this error - 'Deny from' and 'Options -Indexes'.

                    ______

                    CONTENTS OF THE HT.ACCESS FILE (SITTING IN ROOT):

                    # deny access to _all_ files in the core, including changelog.txt and error.log
                    # original borrowed from owncloud
                    
                    # line below if for Apache 2.4
                    <ifModule mod_authz_core.c>
                        Require all denied
                    </ifModule>
                    
                    # line below if for Apache 2.2
                    <ifModule !mod_authz_core.c>
                        deny from all
                        Satisfy All
                    </ifModule>
                    
                    # section for Apache 2.2 and 2.4
                    IndexIgnore *



                    CONTENTS OF THE .HTACCESS FILE IN ROOT

                    # 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]
                    RewriteEngine On
                    RewriteBase /
                    #
                    #
                    # 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



                    CONTENTS OF THE .HTACCESS FILE IN THE CORE DIRECTORY

                    IndexIgnore */*
                    <Files *>
                    Order Deny,Allow
                    Deny from all
                    </Files>

                    This is the .htaccess file in core


                    IndexIgnore */*
                    <Files *>
                    Order Deny,Allow
                    Deny from all
                    </Files>
                    # 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]

                    RewriteEngine On
                    RewriteBase /




                    # 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


                    <IfModule mod_rewrite.c>
                    Options +FollowSymlinks
                    RewriteEngine On

                    # Adaptive-Images -----------------------------------------------------------------------------------

                    # Add any directories you wish to omit from the Adaptive-Images process on a new line, as follows:
                    # RewriteCond %{REQUEST_URI} !some-directory
                    # RewriteCond %{REQUEST_URI} !another-directory

                    RewriteCond %{REQUEST_URI} !assets

                    # Send any GIF, JPG, or PNG request that IS NOT stored inside one of the above directories
                    # to adaptive-images.php so we can select appropriately sized versions
                    RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

                    # END Adaptive-Images -------------------------------------------------------------------------------
                    </IfModule>
                      • 36582
                      • 463 Posts
                      You seem to be contradicting yourself - what is in the .htaccess file in public_html?
                        Web site design in Nottingham UK by Chris Fickling http://www.chrisficklingdesign.co.uk