难住了! .htaccess 正则表达式 RewriteRule 问题

发布于 2024-12-09 20:01:45 字数 652 浏览 0 评论 0原文

如果这已经在其他地方解释过,请原谅我。在过去的两个小时里我一直在谷歌搜索和尝试,但仍然无法让它工作。到目前为止我发现的例子似乎都不太合适。

这看起来应该非常简单。我正在尝试重写以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2024-12-16 20:01:45

您应该能够使用

RewriteRule ^product/(\d+)$ product.cfm?item=$1 [L]

RewriteRule ^speakers/(\d+)$ parts.cfm?part=$1 [L]

实现您的目标。

第一部分是传入的 URL,第二部分是您实际希望服务器使用的部分。看来你现在把它们搞混了。

You should be able to use

RewriteRule ^product/(\d+)$ product.cfm?item=$1 [L]

and

RewriteRule ^speakers/(\d+)$ parts.cfm?part=$1 [L]

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文