大家好,如何使用 .htaccess 删除文件扩展名。
例如:
文件名为 "/home.php"。
当然,在使用 .htaccess 后,可以使用链接 "/home" 访问该文件。
如果访问者访问 "/home.php" 而不是 "/home",则可以将其重定向到 404 错误页面。
谢谢!
Multiviews
:Options +Multiviews
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+([^\?\ ]+)\.php
RewriteRule ^ /%1 [L,R=301]
/home.php
重定向到/home
,但如果您坚持返回“未找到”,则可以将方括号中的301
替换为404
。这段代码将把 *.php
重写为 *
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
您可以在您的.htaccess
文件中使用此重写规则来移除php
扩展名
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
敬礼,
来源:http://alexcican.com/post/how-to-remove-php-html-htm-extensions-with-htaccess/