mod_rewrite .htaccess causing 500 server error if URl does not exist

前端 未结 2 548
闹比i
闹比i 2020-12-12 01:31

I\'ve just started using mod_rewrite, this is what I use for a quite basic structured website with multiple language support:

RewriteEngine on
ErrorDocument          


        
2条回答
  •  抹茶落季
    2020-12-12 02:06

    Helmut, try this (the last rule is the reason for the 500 internal error, and this also includes the suggestion of @DaveRandom to merge rule 2 and 3):

    RewriteEngine on
    ErrorDocument 404 /error404.php
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z]{2})/([^/]+)$ $2.php?lang=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z]{2})/?$ index.php?lang=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9]+)$ $1.php [L]
    

提交回复
热议问题