使用.htaccess删除.php


remove .php with .htaccess

我正在我的站点var/www/mysite/的路径中创建一个.htaccess文件,以删除我的文件".php",但不起的作用

# Apache Rewrite Rules
 <IfModule mod_rewrite.c>
 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
</IfModule>

这是我第一次这样做,如果我做得不好,或者这是否在正确的地方,所以我来找你。

在站点根目录中尝试此代码。htaccess:

Options +FollowSymLinks
RewriteEngine On
# Add trailing slash to url that is not a file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?[^/])$ %{REQUEST_URI}/ [L,R=302,NE]
# Add .php extension from urls internally
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php 
相关文章: