初学者 URL 重写 htaccess
我只想重写所有请求:
http://example.com/products/product.cfm?id=product-name
to
http://example.com/products/product-name
和 其次,
http://example.com/category.cfm?id=some-category&sub=sub-category
to
http://example.com/some-category/sub-category
这是我尝试过的:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^products/$1 ^products/product.cfm?id=$1 [NC]
我确信这没有意义,因为我真的不知道我在做什么。我希望有人能告诉我哪里出错了,这样我就可以以身作则。
谢谢! 乔治
I would simply like to rewrite all requests from:
http://example.com/products/product.cfm?id=product-name
to
http://example.com/products/product-name
and secondly,
http://example.com/category.cfm?id=some-category&sub=sub-category
to
http://example.com/some-category/sub-category
Here is what I’ve tried:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^products/$1 ^products/product.cfm?id=$1 [NC]
I'm sure that makes no sense, as I really have no idea what I am doing. I was hoping someone could show me where I'm going wrong so I could follow by example.
Thanks!
George
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用
mod_rewrite
,您可以这样写:这将进行您想要的翻译,同时保留原始 URL 中的其他参数。它不会处理类别,但我不确定您是否可以按照您的描述同时操作这两个类别。
Using
mod_rewrite
, you could write:This will do the translation you wanted, while preserving other parameters in the original URL. It won't handle categories, but I'm not sure you can have those both in operation simultaneously as you described.
大致思路如下:
RewriteRule 中的 R 标志强制进行硬重定向(访问者的位置栏将更改为新的 URL)。删除此标志以进行内部重定向。
Something along these lines:
The R flag in the RewriteRule forces a hard redirect (the visitor's location bar will change to the new URL). Remove this flag for an internal redirect.
http://www.addedbytes.com/for-beginners/url -rewriting-for-beginners/
我不喜欢纯粹的“链接”答案,但上面的链接对我非常有帮助:]
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
I don't like pure "link" answers, but the link above is extremely helpful to me :]