gpt4 book ai didi

apache - 重写 URL SEO

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:46:00 25 4
gpt4 key购买 nike

我的网站有这样的 url

http://www.mydomain.com/index.php?page=doctors&docid=99

使用SEO重写

RewriteRule ^doctors/([0-9]+)/(.*).html$ index.php?page=doctors&docid=$1 [L]

我明白了

www.mydomain.com/doctors/13/Dr.-John-Smith.html

但我想要一个像这样更友好的 url

www.mydomain.com/Dr.-John-Smith.html

我怎样才能获得这个 url。

最佳答案

重写查询字符串

如果您受雇从头开始重新创建现有网站,您可以使用 URL 重写将旧网站上 20 个最常用的 URL 重定向到新网站上的位置。这可能涉及将 prod.php?id=20 之类的内容重定向到 products/great-product/2342,它本身会重定向到实际的产品页面。

Apache 的 RewriteRule 只适用于 URL 中的路径,不适用于 id=20 这样的参数。要执行此类重写,您需要引用 Apache 环境变量 %{QUERY_STRING}。这可以像这样完成:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=20$
RewriteRule ^prod.php$ ^products/great-product/2342$ [L,R=301]
RewriteRule ^products/(.*)/([0-9]+)$ ^productview.php?id=$1 [L]

在此示例中,第一个 RewriteRule 触发从旧网站 URL 到新网站 URL 的永久重定向。第二条规则将新 URL 重写为显示产品的实际 PHP 页面。

我希望这对您有所帮助,在这里可以找到更多关于重写的信息: http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/

它的布局非常简单。希望对您有所帮助,如果您有任何其他问题,请告诉我。谢谢。

关于apache - 重写 URL SEO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16202789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com