How do I make URLs case insensitive in Linux server

后端 未结 4 1741
被撕碎了的回忆
被撕碎了的回忆 2020-12-05 05:17

I am working a website which is deployed on a Linux server. I have small changes to do on that. I have folder read. The requirement is that if I enter the URL <

相关标签:
4条回答
  • 2020-12-05 05:47

    You can easily make the apache webserver ignore the case by using the mod_speling module, which is part of the standard apache distribution:

    CheckSpelling On
    CheckCaseOnly On
    

    After restarting httpd you can access read as Read or READ or read.

    0 讨论(0)
  • 2020-12-05 05:54

    Hi not sure if this helps but this is the simple workabout i have used, it uses a very basic php page but it works for the site i needed it to.

    Place this code in the htaccess file

     AddType application/x-httpd-php .html .htm
     ErrorDocument 404 /404.php
    

    I have then created a php file wit the following..

     <?php
     $aurl = $_SERVER['REQUEST_URI'];
     $lurl = strtolower($aurl);
    
     if($aurl != $lurl){
    header('location:'.$lurl);
     } else {
    header('location:/404.html');
     }
     ?>
    

    Basically it gets the referring url -> stores as $aurl

    it then makes it lowercase -> stores as $lurl

    if they are not matching it then trys to display the lowercase url ($lurl)

    If that fails the page does not exist, the refering url is now the same ( $lurl == $aurl ) so it then redirects to a proper 404 page or can display some extra code..

    0 讨论(0)
  • 2020-12-05 06:00

    Hi I got the solution finally. Placed the below code in /etc/httpd/conf/httpd.conf.

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

    Then restart httpd:

    sudo service httpd restart
    

    And finally verify it is enabled:

    sudo httpd -M | grep speling
    

    That should yield speling_module (shared)

    Thanks for the help for all..

    0 讨论(0)
  • 2020-12-05 06:04

    First install speling_module. Then include LoadModule speling_module modules/mod_speling.so in httpd.conf file and then include

    <IfModule mod_speling.c>
         CheckSpelling On
         CheckCaseOnly On
    </IfModule>
    in httpd.conf, then restart httpd service using service httpd restart command.

    0 讨论(0)
提交回复
热议问题