难住了! .htaccess 正则表达式 RewriteRule 问题
如果这已经在其他地方解释过,请原谅我。在过去的两个小时里我一直在谷歌搜索和尝试,但仍然无法让它工作。到目前为止我发现的例子似乎都不太合适。
这看起来应该非常简单。我正在尝试重写以下 URL(原始 URL 和目标 URL):
/product.cfm?item=17
/product/17
并且
/parts.cfm?part=12
/speakers/12
...但我无法让任何内容发挥作用。
我已经尝试过类似的操作:
RewriteCond %{QUERY_STRING} ^part=(.*)$ [NC]
RewriteRule ^/parts.cfm$ /parts/$1 [NC,R=301]
但是
RewriteRule ^/parts.cfm?part=(.*)$ /parts/$1 [NC,R=301]
我只是收到一个 404 页面,这表明它没有通过。而且,遗憾的是,我无权访问该服务器上的日志,因此我看不到到底发生了什么。
我这一切都错了吗?还有其他方法可以处理这些吗?这可能只是一个字符的拼写错误,不是吗?
非常感谢任何帮助。谢谢!
Please forgive me if this has been explained elsewhere already. I've been Googling and trying things for the last two hours and still can't get it working. None of the examples I've found so far seem to quite fit.
This seems like it should be incredibly simple. I'm trying to rewrite the following URLs (original and target):
/product.cfm?item=17
/product/17
and
/parts.cfm?part=12
/speakers/12
...and I can't get anything to work.
I've tried things like:
RewriteCond %{QUERY_STRING} ^part=(.*)$ [NC]
RewriteRule ^/parts.cfm$ /parts/$1 [NC,R=301]
and
RewriteRule ^/parts.cfm?part=(.*)$ /parts/$1 [NC,R=301]
But I'm just getting a 404 page, that indicates that it's not going through. And, sadly, I don't have access to logs on this server, so I can't see what's really going.
Am I going about this all wrong? Is there some other way to handle these? It's probably just a one-character typo, isn't it?
Any help is much appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够使用
并
实现您的目标。
第一部分是传入的 URL,第二部分是您实际希望服务器使用的部分。看来你现在把它们搞混了。
You should be able to use
and
to accomplish your goals.
The first part is the incoming URL - the second part is the part that you actually want the server to use. Looks like you've got them mixed up right now.