Using .htaccess to remove PHP file extension from URL

后端 未结 6 1636
名媛妹妹
名媛妹妹 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:27

    You don't use htaccess to do this, you use your app to remove the extensions, and htaccess to map extension-less urls to real files. This rule

    # Remove file extension
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule (.*) $1.php [L]
    

    Says, "if the requested resource doesn't exist as a file, look for the resource with a .php extension". So you remove the extension from all links in your app, and this rule will make the php file run without the extension. Your htaccess is fine as-is, you need to update your app.

提交回复
热议问题