Unexpected behavior with custom .htaccess rewrite rules

前端 未结 1 413
离开以前
离开以前 2021-01-28 16:46

So I have been working on some rewrite rules which aren\'t working as expected. These are some sample requests I am trying to rewrite:

/             -> /index         


        
1条回答
  •  心在旅途
    2021-01-28 16:52

    You have many redundant directives in your .htaccess. Replace all of your .htaccess with this:

    # Turn off mod_spelling
    
       CheckSpelling off
       CheckCaseOnly off
    
    
    Options -MultiViews
    RewriteEngine On
    RewriteBase /
    
    # block direct access to file and directories in these directories
    RewriteCond %{REQUEST_URI} !\.(?:jpe?g|gif|bmp|png|tiff|css|js)$ [NC]
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(Templates|Files) - [NC,F]
    
    # remove index.php
    RewriteCond %{THE_REQUEST} /index\.php [NC]
    RewriteRule ^(.*?)index\.php$ /$1 [L,R=301,NC,NE]
    
    # Redirect Trailing Slashes
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    
    # Handle Front Controller
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(Download|Teaching)/([\w-]+)/?$ index.php?page=$1&id=$2 [L,QSA,NC]
    
    RewriteRule ^(Home)?/?$ index.php?page=Home [L,NC,QSA]
    

    Make sure to clear your browser cache before testing this.

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