如何缩短URL扩展以使其更友好


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

你需要kep其他参数太

更新:以上规则不仅适用于turkey_villas,也适用于其他*.php名称

RewriteRule ^turkey_villas$ villas.php?bid=$1&page=$2 [NC,L]

在"villags.php"文件中获得这样的出价$_get['bid'];