[英]Remove multiple parameters and rewrite url Htaccess
I am trying to rewrite the following Url for SEO and userfriendly purposes using htaccess or other solution. 我正在尝试使用htaccess或其他解决方案重写以下Url用于SEO和用户友好目的。 I have searched and found many answers but none gives me multiple parameters and i am not advance at this. 我已经搜索并找到了很多答案,但没有一个给我多个参数,我没有在这方面取得进展。
mysite.com/myfile.php?dept=1&prodid=161&user=2018&ulevel=1&parentcust=1&prodname=My widget
to 至
mysite.com/products/mywidget
if My Widget has spaces or apostrophes i need them removed. 如果我的小工具有空格或撇号我需要删除它们。 example the product Tiger's eye widget
should be tigerseyewidget
or tigers-eye-widget
例如, Tiger's eye widget
应该是tigerseyewidget
或tigers-eye-widget
You don't have to solve your problem with rewrites only. 您不必仅使用重写来解决问题。
For starters, let's strip your query string: 首先,让我们去掉你的查询字符串:
After stripping that, all you're left with is myfile.php?dept=1&prodid=161 - now that's something that's much easier to rewrite! 在剥离之后,你剩下的就是myfile.php?dept = 1&prodid = 161 - 现在这是更容易重写的东西!
How to rewrite is another question. 如何改写是另一个问题。 There are plenty examples on SO how to rewrite a query string based request to a "pretty url". 有很多关于如何将基于查询字符串的请求重写为“漂亮网址”的示例。 Changing Tiger's eye widget
to tigers-eye-widget
is also well documented. 将Tiger's eye widget
改为tigers-eye-widget
也有很好的记录。
But.. who generates these links? 但是..谁生成这些链接? If you generate these links, why not turn it around and link your products to eg mysite.com/tigers-eye-widget.html and then in PHP map "tigers-eye-widget.html" to product id 161 & dept 1? 如果您生成这些链接,为什么不转过它并将您的产品链接到例如mysite.com/tigers-eye-widget.html,然后在PHP中将“tigers-eye-widget.html”映射到产品ID 161和dept 1?
Your problem should really only apply to legacy URL's that people may have bookmarked or still appear in search results. 您的问题应该仅适用于人们可能已添加书签或仍会显示在搜索结果中的旧版网址。 But for those cases it's perfectly acceptable to redirect them instead of rewriting them. 但对于那些情况,重定向它们而不是重写它们是完全可以接受的。 So you can keep the mapping in a database or textfile, process the request with PHP and do a 301 redirect to the new URL - that way you tell search engines to replace the old URL with the new one and you don't have to worry about complicated multiple .htaccess rewrite rules. 因此,您可以将映射保留在数据库或文本文件中,使用PHP处理请求并执行301重定向到新URL - 这样您就可以告诉搜索引擎将旧URL替换为新URL,您不必担心关于复杂的多个.htaccess重写规则。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.