[英]How can I shorten URL extentions to make them more friendly
我們有這樣顯示的鏈接,
turkish-property-world.com/turkey_villas.php?bid=4&page=1
想展示,
turkish-property-world.com/turkey_villas
在.htaccess中,我們包含了規則,但沒有任何變化。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
有什么幫助嗎?
有一個Javascript解決方案,它很簡單,但不是很優雅。 仍然:
//get the url
$old_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
//remove everything after '.php' in the url
$new_url = substr($old_url, 0, strpos($old_url, '.php'));
//then with javascript you replace the url with the new one
<script type="text/javascript">
if(new_url != '')
{
window.history.replaceState({"html":'Title',"pageTitle":'Page Title'}, '', new_url);
}
</script>
您可以使用以下內容;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ $1.php?bid=$2&page=$3 [L]
通過做這個,
turkish-property-world.com/turkey_villas.php?bid=4&page=1
將會
turkish-property-world.com/turkey_villas/4/1
您還需要保留其他參數
更新:以上規則不僅適用於turkey_villas
,還將適用於其他* .php名稱
RewriteRule ^turkey_villas$ villas.php?bid=$1&page=$2 [NC,L]
在“ villas.php”文件中,像這樣$ _GET ['bid'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.