使用 .htaccess 文件的动态 URL
我想将 URL 转换
http://mysite.com/search/search_mgmt.php?CategoryID=1
为类似
http://mysite.com/search/my-seo-friendly-url
我启用了 mod_rewrite 的内容。
I'd like to convert a URL like
http://mysite.com/search/search_mgmt.php?CategoryID=1
to something like
http://mysite.com/search/my-seo-friendly-url
I have mod_rewrite enabled.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想实现什么目标?如果某些内容通过
search/search_mgmt.php?CategoryID=1
进入您的网站,并且您想将其转换为search/my-seo-Friendly-url
,您将拥有将流量重定向到另一个 URL:使用此规则,服务器将发送客户端代码
301 Moved Permanently
,并将Location:
标头设置为新 URL。您可以将 301 代码更改为 302(找到):[R=302,L]
。 (注意:在这种情况下,客户端会向您的服务器发送两个请求来获取内容。)如果您不添加此结果说明符,那么您的服务器将仅返回结果,就像使用重写的 URL 访问一样。所以我猜您实际上希望用户看到您的
my-seo-friend-url
而在服务器上它将由search_mgmt.php?CategoryID=1
处理。你可以这样做:What do you want to achieve? If somethings gets to your site with
search/search_mgmt.php?CategoryID=1
and you want to convert it tosearch/my-seo-friendly-url
, you will have to redirect traffic to another URL:With this rule, the server will send the client code
301 Moved Permanently
withLocation:
header set to the new URL. You can change 301 code to 302 (Found):[R=302,L]
. (Note: in this case the client sends two requests to your server to get the content.)If you don't add this result specifier, then your server will just return the result as if it was accessed with re-written URL. So I guess you actually would like users to see your
my-seo-friendly-url
whereas on the server it would be handled bysearch_mgmt.php?CategoryID=1
. You can do it this way: