Apache cannot detect and rewrite URLs to lowercase












0















What am I trying to achieve?



I want to convert all URL's that are within the /migrate directory (and subdirectories) to lowercase.



What have I done?



I have migrated my website from DNN to Wordpress. Therefore I have URL's in my posts that reference images with a combination of upper and lowercase letters.



All of my directories and files on disk in the /migrate folder (and subfolders) are lowercase.



When I view an article, if the reference to the image has an uppercase character, I am getting a 404 which is expected.



For example:



https://xxx.domain.net/wp-content/migrate/ABC/image.jpg



https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg



https://xxx.domain.net/wp-content/migrate/abc/Image.jpg



https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg



So after reading various articles online and on here I tried a few things:



1) Enabled mod_speling and added this to apache2.conf



LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
<IfModule mod_speling.c>
CheckSpelling On
CheckCaseOnly On
</IfModule>


This didn't work, continued to get 404's.



2) Tired to use Rewritemap in my /etc/sites-enabled/mysite.conf file.



RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} /migrate [A-Z]
RewriteRule ^(.*)$ /${lc:$1} [R=301,L]


However this would rewrite all URL's to lowercase and it broke some of the Wordpress plugins and editors as the files on disk had uppercase characters.



My .htaccess file in the Wordpress root directory is as follows:



RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

#BEGIN Wordpress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress









share|improve this question





























    0















    What am I trying to achieve?



    I want to convert all URL's that are within the /migrate directory (and subdirectories) to lowercase.



    What have I done?



    I have migrated my website from DNN to Wordpress. Therefore I have URL's in my posts that reference images with a combination of upper and lowercase letters.



    All of my directories and files on disk in the /migrate folder (and subfolders) are lowercase.



    When I view an article, if the reference to the image has an uppercase character, I am getting a 404 which is expected.



    For example:



    https://xxx.domain.net/wp-content/migrate/ABC/image.jpg



    https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg



    https://xxx.domain.net/wp-content/migrate/abc/Image.jpg



    https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg



    So after reading various articles online and on here I tried a few things:



    1) Enabled mod_speling and added this to apache2.conf



    LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
    <IfModule mod_speling.c>
    CheckSpelling On
    CheckCaseOnly On
    </IfModule>


    This didn't work, continued to get 404's.



    2) Tired to use Rewritemap in my /etc/sites-enabled/mysite.conf file.



    RewriteMap  lc int:tolower
    RewriteCond %{REQUEST_URI} /migrate [A-Z]
    RewriteRule ^(.*)$ /${lc:$1} [R=301,L]


    However this would rewrite all URL's to lowercase and it broke some of the Wordpress plugins and editors as the files on disk had uppercase characters.



    My .htaccess file in the Wordpress root directory is as follows:



    RewriteEngine on
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

    RewriteCond %{HTTPS} !=on
    RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

    #BEGIN Wordpress

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>

    # END WordPress









    share|improve this question



























      0












      0








      0








      What am I trying to achieve?



      I want to convert all URL's that are within the /migrate directory (and subdirectories) to lowercase.



      What have I done?



      I have migrated my website from DNN to Wordpress. Therefore I have URL's in my posts that reference images with a combination of upper and lowercase letters.



      All of my directories and files on disk in the /migrate folder (and subfolders) are lowercase.



      When I view an article, if the reference to the image has an uppercase character, I am getting a 404 which is expected.



      For example:



      https://xxx.domain.net/wp-content/migrate/ABC/image.jpg



      https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg



      https://xxx.domain.net/wp-content/migrate/abc/Image.jpg



      https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg



      So after reading various articles online and on here I tried a few things:



      1) Enabled mod_speling and added this to apache2.conf



      LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
      <IfModule mod_speling.c>
      CheckSpelling On
      CheckCaseOnly On
      </IfModule>


      This didn't work, continued to get 404's.



      2) Tired to use Rewritemap in my /etc/sites-enabled/mysite.conf file.



      RewriteMap  lc int:tolower
      RewriteCond %{REQUEST_URI} /migrate [A-Z]
      RewriteRule ^(.*)$ /${lc:$1} [R=301,L]


      However this would rewrite all URL's to lowercase and it broke some of the Wordpress plugins and editors as the files on disk had uppercase characters.



      My .htaccess file in the Wordpress root directory is as follows:



      RewriteEngine on
      RewriteCond %{HTTP:Authorization} ^(.*)
      RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

      RewriteCond %{HTTPS} !=on
      RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

      #BEGIN Wordpress

      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>

      # END WordPress









      share|improve this question
















      What am I trying to achieve?



      I want to convert all URL's that are within the /migrate directory (and subdirectories) to lowercase.



      What have I done?



      I have migrated my website from DNN to Wordpress. Therefore I have URL's in my posts that reference images with a combination of upper and lowercase letters.



      All of my directories and files on disk in the /migrate folder (and subfolders) are lowercase.



      When I view an article, if the reference to the image has an uppercase character, I am getting a 404 which is expected.



      For example:



      https://xxx.domain.net/wp-content/migrate/ABC/image.jpg



      https://xxx.domain.net/wp-content/migrate/Xyz/image.jpg



      https://xxx.domain.net/wp-content/migrate/abc/Image.jpg



      https://xxx.domain.net/wp-content/migrate/ABC/Xyz/image.jpg



      So after reading various articles online and on here I tried a few things:



      1) Enabled mod_speling and added this to apache2.conf



      LoadModule speling_module /usr/lib/apache2/modules/mod_speling.so
      <IfModule mod_speling.c>
      CheckSpelling On
      CheckCaseOnly On
      </IfModule>


      This didn't work, continued to get 404's.



      2) Tired to use Rewritemap in my /etc/sites-enabled/mysite.conf file.



      RewriteMap  lc int:tolower
      RewriteCond %{REQUEST_URI} /migrate [A-Z]
      RewriteRule ^(.*)$ /${lc:$1} [R=301,L]


      However this would rewrite all URL's to lowercase and it broke some of the Wordpress plugins and editors as the files on disk had uppercase characters.



      My .htaccess file in the Wordpress root directory is as follows:



      RewriteEngine on
      RewriteCond %{HTTP:Authorization} ^(.*)
      RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]

      RewriteCond %{HTTPS} !=on
      RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

      #BEGIN Wordpress

      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteRule ^index.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>

      # END WordPress






      mod-rewrite apache2 lowercase rewritemap






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 23:32









      halfer

      14.7k759116




      14.7k759116










      asked Nov 28 '18 at 22:23









      NanzNanz

      109214




      109214
























          1 Answer
          1






          active

          oldest

          votes


















          0














          After hours and hours of trying different things and reading through the logs, I have worked this out!



          Basically I needed to ignore all the other Wordpress directories from rewriting.



          RewriteMap lc int:tolower
          RewriteCond %{REQUEST_URI} [A-Z]
          RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
          RewriteCond %{REQUEST_URI} !^/wp-content/themes/
          RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
          RewriteCond %{REQUEST_URI} !^/wp-includes/
          RewriteCond %{REQUEST_URI} !^/wp-admin/
          RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528998%2fapache-cannot-detect-and-rewrite-urls-to-lowercase%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            After hours and hours of trying different things and reading through the logs, I have worked this out!



            Basically I needed to ignore all the other Wordpress directories from rewriting.



            RewriteMap lc int:tolower
            RewriteCond %{REQUEST_URI} [A-Z]
            RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
            RewriteCond %{REQUEST_URI} !^/wp-content/themes/
            RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
            RewriteCond %{REQUEST_URI} !^/wp-includes/
            RewriteCond %{REQUEST_URI} !^/wp-admin/
            RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]





            share|improve this answer




























              0














              After hours and hours of trying different things and reading through the logs, I have worked this out!



              Basically I needed to ignore all the other Wordpress directories from rewriting.



              RewriteMap lc int:tolower
              RewriteCond %{REQUEST_URI} [A-Z]
              RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
              RewriteCond %{REQUEST_URI} !^/wp-content/themes/
              RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
              RewriteCond %{REQUEST_URI} !^/wp-includes/
              RewriteCond %{REQUEST_URI} !^/wp-admin/
              RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]





              share|improve this answer


























                0












                0








                0







                After hours and hours of trying different things and reading through the logs, I have worked this out!



                Basically I needed to ignore all the other Wordpress directories from rewriting.



                RewriteMap lc int:tolower
                RewriteCond %{REQUEST_URI} [A-Z]
                RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
                RewriteCond %{REQUEST_URI} !^/wp-content/themes/
                RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
                RewriteCond %{REQUEST_URI} !^/wp-includes/
                RewriteCond %{REQUEST_URI} !^/wp-admin/
                RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]





                share|improve this answer













                After hours and hours of trying different things and reading through the logs, I have worked this out!



                Basically I needed to ignore all the other Wordpress directories from rewriting.



                RewriteMap lc int:tolower
                RewriteCond %{REQUEST_URI} [A-Z]
                RewriteCond %{REQUEST_URI} !^/wp-content/uploads/
                RewriteCond %{REQUEST_URI} !^/wp-content/themes/
                RewriteCond %{REQUEST_URI} !^/wp-content/plugins/
                RewriteCond %{REQUEST_URI} !^/wp-includes/
                RewriteCond %{REQUEST_URI} !^/wp-admin/
                RewriteRule ^/?(.*)$ /${lc:$1} [R=301,L]






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 3 '18 at 9:15









                NanzNanz

                109214




                109214
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53528998%2fapache-cannot-detect-and-rewrite-urls-to-lowercase%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)