.htaccess Messing up with .php extension?

后端 未结 1 560
野性不改
野性不改 2021-01-22 13:53

Ok, so I have this mod_rewrite rule that internally attaches a .html extension if it is not provided when sending the request:

Options +FollowSymLinks
RewriteEngine o         


        
1条回答
  •  有刺的猬
    2021-01-22 14:17

    Try following rules for handling php:

    ## Internally rewrite extensionless file requests to .php files ##
    # If the requested URI does not contain a period in the final path-part
    RewriteCond %{REQUEST_URI} !(\.[^./]+)$
    # and if it does not exist as a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    # and if it does not exist as a file
    RewriteCond %{REQUEST_FILENAME} !-f
    # then add .html to get the actual filename
    RewriteRule (.*) /$1.php [L]
    
    ## Externally redirect clients directly requesting .php page URIs to extensionless URIs
    #
    # If client request header contains html file extension
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+)\.php
    # externally redirect to extensionless URI
    RewriteRule ^(.+)\.php$ /$1 [R=301,L]
    

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