2013-10-24 97 views
0

我想以這種方式實現url localhost/mysite/contact /沒有php擴展名,並在最後添加了尾部斜線但它不工作。刪除php文件擴展名

這是代碼示例:

RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

我如何能實現如下: 本地主機/ mysite的/頁/ 任何幫助嗎? 謝謝。

+0

您的PHP是以「http:// localhost/mysite/contact.php」的身份訪問的嗎? – anubhava

+0

這是正確的。這是http://localhost/mysite/contact.php – test

回答

0

啓用通過httpd.confmod_rewrite.htaccess,然後把這個代碼在你DOCUMENT_ROOT/.htaccess文件:

RewriteEngine On 
RewriteBase /mysite/ 

RewriteRule ^foo/?$ bar [L,NC,R] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{DOCUMENT_ROOT}/mysite/$1.php -f 
RewriteRule ^(.+?)/?$ $1.php [L] 
+0

對不起anubhava。這不起作用。 – test

+0

那麼當你輸入'http:// localhost/mysite/contact'時會發生什麼?你有404嗎?這也在'DOCUMENT_ROOT/.htaccess'或'DOCUMENT_ROOT/mysite/.htaccess'中? – anubhava

+0

找不到對象! 在此服務器上找不到請求的URL。如果您手動輸入網址,請檢查拼寫並重試。 如果您認爲這是服務器錯誤,請與網站管理員聯繫。 錯誤404 localhost Apache/2.4.3(Win32)OpenSSL/1.0.1c PHP/5.4.7 – test

0

確保您已啓用國防部重寫並加載

如 RewriteEngine敘述上

這將工作沒有文件v系統檢查開銷

RewriteRule ^([^。?] +)$%{REQUEST_URI} .php [L]

+0

全碼: RewriteEngine敘述上 RewriteBase/mysite的/ 重寫規則^([^。?] +)$%{REQUEST_URI} .PHP [L] test

+0

我已經得到了同樣的問題重定向! – test