我的网站有一个这样的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。
发布于 2013-04-25 06:00:44
重写查询字符串
如果您受聘从头开始重新创建现有网站,则可以使用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/
它是以一种非常直接的方式布局的。希望这对你有帮助,如果你还有其他问题,请让我知道。谢谢。
https://stackoverflow.com/questions/16202789
复制相似问题