2016-09-28 106 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