2013-04-16 141 views
0

我知道有很多話題,我嘗試了很多次,但它不起作用。在.htaccess文件中隱藏文件擴展名(php)

我想要什麼? 代替example.com/en/file.php用戶只能看到:example.com/en/file

我的.htaccess:

DirectoryIndex index.php index.html 

RewriteEngine on 
*RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ /$1.php* 


ErrorDocument 404 /index.php 

RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
RewriteRule ^ru\/index\.php$ "http\:\/\/example\.com\/ru\/" [R=301,L] 

RewriteCond %{HTTP_HOST} ^example\.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.example\.com$ 
RewriteRule ^en\/index\.php$ "http\:\/\/example\.com\/en\/" [R=301,L] 

等每種語言

1.我添加了什麼來隱藏擴展?

  1. 它工作後應該使用頁面之間的鏈接作爲「file.php」或只有「文件」?
+0

檢查'RewriteRule'語法 - 這是相反的。第一個是「重寫什麼」,第二個是「重寫的結果」 – zerkms

+3

這是我見過的最常見的問題,它不會在發佈之前進行搜索 –

+0

這就像黑客攻擊,使用簡單的PHP框架總是更好。嘗試[CodeIgniter](http://ellislab.com/codeigniter)或[CakePHP](http://cakephp.org/)如果你想給它一個鏡頭:) –

回答

0
DirectoryIndex index.php index.html  

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

在您的鏈接中,請勿使用擴展名。

+0

在 上添加:RewriteEngine RewriteRule ^(。+)$ $ 1.php [L] //不起作用:在此服務器上未找到請求的URL/q_insert_city_image。 此外,嘗試使用ErrorDocument處理請求時遇到500內部服務器錯誤錯誤。 –

+0

我剛編輯的代碼 –

+0

未找到 在此服務器上找不到請求的URL/en/things_to_visit。我不明白爲什麼它不起作用=( –

1

也許是這樣的。 修改爲適合更具體的模式匹配。

RewriteRule ^(?:(.*)/)?(.*)$ $2.php?lang=$1 

重新寫入:

/EN /樂趣=> /fun.php?lang=en

/RU /樂趣=> /fun.php?lang=ru

/fun => /fun.php?lang=

+0

語言沒問題..我更喜歡用可見文件夾 –

+0

@ЖеняТест對不起,不清楚你的意思。 – showdev

0

固定加1行:

RewriteEngine on 
**Options -Multiviews** 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$  $1.php  [L,QSA] 

謝謝! :)

相關問題