可能重複刪除.PHP從URL擴展:
.htaccess hide extension and variables使用.htaccess文件
我想改變我的網址
例如,
從:http://domain-name.com/dir/page1.php 至:http://domain-name.com/dir/?page1
請爲此
我沒有使用任何CMS建議.htaccess文件的代碼。它只是一個簡單的PHP網站。
可能重複刪除.PHP從URL擴展:
.htaccess hide extension and variables使用.htaccess文件
我想改變我的網址
例如,
從:http://domain-name.com/dir/page1.php 至:http://domain-name.com/dir/?page1
請爲此
我沒有使用任何CMS建議.htaccess文件的代碼。它只是一個簡單的PHP網站。
您不希望進行的轉換,因爲?
是代表「此處開始查詢字符串」的URL中的特殊字符。
對於這裏page.php
到page
轉型的代碼:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ $1 [R=301,L]
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ $1 [R=301,L]
RewriteRule ^([^/.]+)$ $1.php [L]
傑弗裏,我用我們的代碼,但它改變了我的網址是:http:// domain-name.com/home/username/public_html/dir/page1和瀏覽器顯示404錯誤 –
我想要那個嗎?因爲它在項目要求中提到。 –
@ChetanPatil,嘗試新的代碼。 – Shoe
'/ DIR/page1'而不是'/ DIR/page1'?爲什麼? – PleaseStand
你可能想讀這個線程: http://stackoverflow.com/questions/8371634/hide-php-extension-htaccess – Yunalescar