Using .htaccess to remove PHP file extension from URL

后端 未结 6 1566
名媛妹妹
名媛妹妹 2021-01-19 02:51

I just finished installing a LAMP stack on Ubuntu 12, and have run into an issue with Apache\'s .htaccess file. I have the rewrite and redirect mods enabled, and the .htacce

6条回答
  •  花落未央
    2021-01-19 03:18

    # Apache Rewrite Rules
     
      Options +FollowSymLinks
      RewriteEngine On
      RewriteBase /
    
    # Add trailing slash to url
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
      RewriteRule ^(.*)$ $1/ [R=301,L]
    
    # Remove .php-extension from url
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME}\.php -f
      RewriteRule ^([^\.]+)/$ $1.php 
    
    # End of Apache Rewrite Rules
     
    

提交回复
热议问题