2016-09-28 125 views

回答

0

试试这个,

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^([^\.|/]+)$ $1.php [NC,L] 
+0

“试试这个“ - 请添加解释。 – DanFromGermany

0
At first check your php.ini settings for Server API if your server api is 1)apache, 2)apache2filter, 3)apache2handler or like then only you can use .htaccess file. In htaccess file if your php version is php5 then use <IfModule mod_rewrite.c> block to write this code 
try this code 
RewriteEngine On 
# Remove .php-extension from url 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^\.]+)/$ $1.php 
2

制作斜线可选在您的规则,并删除目录检查条件:

RewriteEngine on 

RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.+?)/?$ $1.php 
+0

是不是'^(。*)$'贪婪足以匹配字面上的任何东西? – DanFromGermany

+0

是的,这是真的,这就是为什么我用'。+?'使它成为一个懒惰的匹配。 – anubhava

+0

啊..所以它不会像'index /?var = 123.php'这样疯狂的东西 – DanFromGermany