簡體   English   中英

.htaccess文件不適用(刪除.php擴展名)

[英].htaccess file did not apply (removing .php extension)

我嘗試僅通過使用XAMPP本地服務器上的.htaccess文件來刪除.php擴展名。 我在其中添加了以下幾行:

RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks
Options -Multiviews
## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

我嘗試了更多選擇來實現自己的目標,但沒有任何改變。 我做錯什么了嗎?

檢查httpd.conf文件(apache的配置文件)中是否具有AllowOverride All 如果在Windows上使用XAMPP,則httpd.conf文件應位於以下目錄中:C:\\ xampp \\ apache \\ conf \\ httpd.conf

在目錄標記中添加AllowOverride All行。 例如: <Directory C:\\xampp\\htdocs> AllowOverride All Allow from all </Directory>

PS通過允許覆蓋,您告訴服務器允許.htaccess文件覆蓋服務器的默認配置。

編輯:對不起,我之前提到過AllowOverride'On'。 它應該是AllowOverride'All'。 這在我的Ubuntu上正常工作。 我將盡快找出如何使其在Windows(xampp)中工作的方法。

以下在apache2上對我有用。 希望它也可以在XAMPP上運行。 , and that the PHP file exist. 這幾乎與您的代碼相同,但是它檢查所請求的文件名 ,並且PHP文件存在。

RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks
Options -Multiviews
## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ %{REQUEST_FILENAME}\.php [NC,L]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM