在Ubuntu 14.04上運行Apache 2。 rewrite_module已啓用(sudo apachectl -M
)。Apache - 使用httpd.conf中的mod_rewrite刪除.php和.html文件擴展名
在/etc/apache2/apache2.conf中(httpd.conf中的Ubuntu的版本)我有以下代碼塊:
<Directory /var/www/>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.php
RewriteCond /%{REQUEST_FILENAME}.html -f
RewriteRule ^([a-zA-Z0-9_-\s]+)/$ /$1.html
</IfModule>
<IfModule mod_expires.c>
...
<IfModule mod_headers.c>
...
</IfModule>
</IfModule>
</Directory>
然sudo service apache2 restart
。
當我訪問我的服務器上沒有.php文件擴展名的URL時,我得到了404!爲什麼這不起作用?
對不起,那也沒有工作。 :( – torjinx