假设有个网页
http://www.example.com/index.html
http://www.example.com/index.php
如果我们想要隐藏.html后缀或者.php后缀
http://www.example.com/index
http://www.example.com/index
由于Apache和Nginx的.htaccess语法不同,这里提供2种方法。
一、Apache
- 隐藏.html后缀
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.html [NC,L]
- 隐藏.php后缀
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ $1.php [NC,L]
二、Nginx
location / { try_files $uri $uri/ $uri.php$is_args$args; }
- 隐藏.html后缀
if (!-f $request_filename){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ rewrite ^/([^\.]+)$ /$1.html last; }
- 隐藏.php后缀
if (!-f $request_filename){ set $rule_0 1$rule_0; } if ($rule_0 = "1"){ rewrite ^/([^\.]+)$ /$1.php last; }
利用.htaccess隐藏html和php后缀
APACHE 伪静态设置
nginx一招配置,帮你快速隐藏php后缀名