Htaccess删除.php扩展名为.html的URL
问题描述:
要从网址中删除.php扩展名并用.html
i代替,
To remove .php extension from URL and replaced with .html i have wrote:
Options -Indexes
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php $1.html [QSA,L]
此工作正常,扩展名已更改,但我收到此消息:
This work fine and i the extension changed, but i get this message:
Not Found
The requested URL /**xxxxxx**.html was not found on this server.
答
投放 .php
文件作为 .html
,您可以使用以下代码:
To serve .php
files as .html
you can use this code:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1.html [R=302,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)\.html$ $1.php [L,NC]