我已經創建了網站,我想更改其網址結構。例如, 。我無法更改我的PHP網站中的URL結構
http://www.haitibravo.com/market/detail.php?add_id=73
我想不顯示它?標記像
http://www.haitibravo.com/market/product/73
我如何顯示這樣的網址。請幫幫我。我嘗試了很多技巧,但我失敗了。
我已經創建了網站,我想更改其網址結構。例如, 。我無法更改我的PHP網站中的URL結構
http://www.haitibravo.com/market/detail.php?add_id=73
我想不顯示它?標記像
http://www.haitibravo.com/market/product/73
我如何顯示這樣的網址。請幫幫我。我嘗試了很多技巧,但我失敗了。
製作一個.htaccess文件並在其中保存下面的代碼。
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?r=$1
RewriteRule ^([a-zA-Z0-9_-]+)/item/$ index.php?r=$1
我應該將這些行添加到.htaccess文件? –
是的。還有一件事,如果你在localserver上運行它。然後搜索谷歌如何運行.htaccess您使用的本地主機上的軟件。 – Abdullah
否否我在我的網站上運行它 –
RewriteEngine On
/* this enables you to write urls in desired fashion */
RewriteRule ^([a-zA-Z0-9_-]+)$ detail.php?add_id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/product/$ detail.php?add_id=$1
/*Something like this should redirecto from detail.php?add_id=n to your desired url */
RewriteCond %{THE_REQUEST} /(?:detail\.php)?\?add_id=([^&\s]+) [NC]
RewriteRule^item/%1? [R=302,L,NE]
/* You may need to play with the above slightly... */
谷歌'阿帕奇國防部重寫examples'或'現代重寫引擎友好URLs' –
我很抱歉,我無法理解你在說什麼。你可以請給我一些例子 –