We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 54362
    • 6 Posts
    Friendly URLs and migration to HTTPS SSL - only the homepage is served correctly on HTTPS. All other pages using friendly URLS result in 404 page not found

    Recently installed a SSL certificates on the site running MODX. Check the site was still working after the certificate installation and found that only the homepage would render correctly. All the other pages, with friendly URLS enabled, would result in a 404 when running under https. If friendly URLs are turned off, then all the pages work fine under https.

    I have cleared all caches from within MODX Manager and restarted Apache countless times.

    The MODX Manager quite happily redirects (and works) from http://my-domain.tld/manager/ to https://my-domain.tld/manager/ and http://www.my-domain.tld/manager/ (note the www) redirects to https://my-domain.tld/manager/

    Having read several pages on here, and tried all the solutions, I am no closer to getting friendly URLs to work under https.

    Pages read:

    Environment:

    • MODX Version: 2.6.3-pl (system info report screen) - 2.6.1-pl shown in upper left corner of Manager
    • PHP Version: [b]5.6.36
    • Server Info: CentOS 6.10 Final (Linux Kernel 2.6.32-754.el6.x86_64)

    System settings:
    Server type (server_protocol): https

    Friendly URL Area in System settings
    Automatically generate (alias automatic_alias): Yes
    Container Suffix (container_suffix): /
    FURL Lowercase Aliases (friendly_alias_lowercase_only): Yes
    FURL Alias Maximum Length (friendly_alias_max_length): 0
    FURL Alias Real-Time (friendly_alias_realtime): No
    FURL Alias Character Restriction Method (friendly_alias_restrict_chars): pattern
    FURL Alias Character Restriction Pattern (friendly_alias_restrict_chars_pattern): /[\0\x0B\t\n\r\f\a&=+%#<>"~:`@\?\[\]\{\}\|\^'\\]/
    FURL Alias Strip Element Tags (friendly_alias_strip_element_tags): Yes
    FURL Alias Transliteration (friendly_alias_translit): none
    FURL Alias Transliteration Service Class (friendly_alias_translit_class): translit.modTransliterate
    FURL Alias Transliteration Service Class Path (friendly_alias_translit_class_path): {core_path}components/
    FURL Alias Trim Characters (friendly_alias_trim_chars): /.-_
    FURL Alias Word Delimiter (friendly_alias_word_delimiter): -
    FURL Alias Word Delimiters (friendly_alias_word_delimiters): -_
    Use Friendly URLs (friendly_urls): No
    Use Strict Friendly URLs (friendly_urls_strict): No
    Check for Duplicate URIs Across All Contexts (global_duplicate_uri_check): No
    Use Friendly Alias Path (use_alias_path): No
    Use Frozen Parent URIs (use_frozen_parent_uris): No

    .htaccess file (syntax checked and it was all good)

    # 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} !^my-domain.tld$ [NC]
    RewriteRule (.*) https://my-domain.tld/$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\. [NC]
    #RewriteCond %{HTTP_HOST} (.+)$
    #RewriteRule ^(.*)$ https://www.%1/$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://my-domain.tld/$1 [R=301,L]



    # Redirect the manager to a specific domain - don't rename the ht.access file
    # in the manager folder to use this this rule
    #RewriteCond %{HTTP_HOST} !^example-domain-please-change\.com$ [NC]
    #RewriteCond %{REQUEST_URI} ^/manager [NC]
    #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]



    I feel there is just one, obvious, setting or typo somewhere that I am missing and cannot for the life of me find it. Any help would be greatly appreciated and hopefully it will help someone else out in the future.

    Thanks Richard

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

      • 3749
      • 24,544 Posts
      Do you have this tag (with the exclamation point) in the head section of all 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
        • 54362
        • 6 Posts
        Hi BobRay,

        Thanks for your response. I originally just has
        <base href="/" />
        in all templates, then tried
        [[!+site_url]]
        as you suggested here (and in another thread), but sadly I still got the same result - 404 page not found.
        What does the combination of [[!+site_url]] and Friendly URLs enabled do to links within a MODX site?
          • 46886
          • 1,154 Posts
          You will also need to use [[!+site_url]] to link to your css files in your <head> in order to preserve ssl. As in

           <link rel="stylesheet" href="[[!++site_url]]css/filename.css" type="text/css">


          I've been trying to get into my server all day to send you my htaccess, but the client site of my hoster is down, still...

          Bob are there any system settings that might be related? I just went through ssl and definitely have friendly urls working so it could solve the problem

          Finally! Working htaccess

          # 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]
          
          # Prevent Apache from serving .htaccess files:
          <FilesMatch "^\.htaccess">
              Order allow,deny
              Deny from all
          </FilesMatch>
          
          # <IfModule mod_security.c>
          # SecFilterEngine Off 
          # SecFilterScanPOST Off
          # </IfModule>
          
          Options All -Indexes
          Options +FollowSymlinks
          
          RewriteEngine On
          RewriteBase /
          
          
          RewriteCond %{HTTP_HOST} domain\.com [NC]
          RewriteCond %{SERVER_PORT} 80
          RewriteRule ^(.*)$ https://domain.com/$1 [R,L]
          
          
          # 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]
          
          # 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
          [ed. note: nuan88 last edited this post 5 years, 9 months ago.]
            • 3749
            • 24,544 Posts
            What does the combination of [[!+site_url]] and Friendly URLs enabled do to links within a MODX site?

            It prepends the site URL to any internal links on the site. So for an image tag:

            <img src="assets/photo1.jpg" />


            gets translated to:

            <img src="https://yoursite/com/assets/photo1.jpg" />


            Note the lack of a leading slash in the original img tag. site_url always ends in a slash.


            The site_url System setting is actually created on-the-fly, based on the URL the visitor uses to access the site.

            I should have asked this earlier, but all your internal links are in the form of link tags, right?

            This would link to the resource with the ID 12:

            <a href=[[~12]]>Link Text</a>
            [ed. note: BobRay last edited this post 5 years, 9 months ago.]
              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
              • 54362
              • 6 Posts
              @nuan88: Thanks for finding your .htaccess file. I copied what you have (and adjusted accordingly), but no difference. I changed all my CSS paths to include [[!+site_url]] too.

              @BobRay: All links are referencing the MODX IDs.

              Regarding base href, I knew what it does, but I was not sure MODX worked with it differently when certain setting (friendly URLs in this case) were enabled.

              I took forgot to mention that the 404 happens without using links. If you go directly to a friendly URL page you get the 404. Also, when previewing a page from the MODX Manager I also get 404.

              I think my next step is to try and replicate the site elsewhere with SSL and go through it step my step from a fresh.
                • 46886
                • 1,154 Posts
                @orangekiwi have you enabled friendly urls in system settings? there are a couple of system settings for friendly urls
                  • 3749
                  • 24,544 Posts
                  Use Friendly URLs (friendly_urls): No

                  That should definitely be "Yes" if you've enabled FURLs in .htaccess.

                  BTW, can you reach pages by ID:

                  yoursite.com/index.php?id=12


                  It's also worth manually deleting all files in the core/cache directory to make sure your new setting are taking effect.

                    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
                    • 54362
                    • 6 Posts
                    You are both right, friendly_urls is actually set to Yes. Unfortunately I didn’t check that line before I posted (I copied it when I was tracking what settings gave what results). Prior to the SSL certificate being installed friendly urls worked flawlessly.
                    I will create a fresh MODX installation on a server with an SSL certificate that has been installed prior to installation of MODX itself and report back. I’m thinking something might have become corrupted with the certificate installation.

                    Once again, thank you both for your replies.

                    Richard
                      • 3749
                      • 24,544 Posts
                      To cope with problems people might have with SSL in one of my extras, I actually included the cert file with the extra and set the path to it.
                        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