301 htaccess 重定向动态 url 需要帮助
我正在尝试将此
hhttp://www.website.net/forum/index.php?showtopic=12345
重定向到
hhttp://www.website.ORG/forum/t12345
12345动态主题 ID
如果在主题 ID 之后找到任何信息,我还需要将其删除,例如
hhttp://www.website.net/forum/index.php?showtopic=12345&view=getlastpost
我想要 &view=getlastpost 或任何可能出现在要删除的 ID 号后面的类似内容。
我尝试过
RewriteCond %{QUERY_STRING} ^(([^&]&))showtopic=([^&]+)&?(.*)?$ RewriteRule ^index.php$ http://www.website.org/forum /t%3?%1%4/ [L,R=301]
但它不起作用。我的 URL 中出现垃圾。
hhttp://www.website.org/forum/index.php?showtopic=29294&view=getlastpost (when that link is clicked - the result is hhttp://www.website.net/forum/t29294?view=getlastpost/)
hhttp://www.website.org/forum/index.php?showtopic=29029 (when that link is clicked - the result is hhttp://www.website.net/forum/t29029?/).
我怎样才能清除它?
I'm trying to redirect this
hhttp://www.website.net/forum/index.php?showtopic=12345
to
hhttp://www.website.ORG/forum/t12345
12345 being the dynamic topic ID
I also need any information to be stripped away if it is found after the topic ID, for example
hhttp://www.website.net/forum/index.php?showtopic=12345&view=getlastpost
I want &view=getlastpost or any similar that may appear after the ID number to be get rid of.
I've tried
RewriteCond %{QUERY_STRING} ^(([^&]&))showtopic=([^&]+)&?(.*)?$
RewriteRule ^index.php$ http://www.website.org/forum/t%3?%1%4/ [L,R=301]
but it didn't work. I get trash in the URL.
hhttp://www.website.org/forum/index.php?showtopic=29294&view=getlastpost (when that link is clicked - the result is hhttp://www.website.net/forum/t29294?view=getlastpost/)
hhttp://www.website.org/forum/index.php?showtopic=29029 (when that link is clicked - the result is hhttp://www.website.net/forum/t29029?/).
How can I clear it out?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
$2 意味着有两个括号区域,但我在您的规则中只看到一个,因此将其更改为 $1。
此外,您的 URL 以 /forum/ 开头,因此需要将其包含在规则中。
还有 .如果您不希望将 index.php 中的 视为正则表达式特殊字符,则需要对其进行转义。
如果你想放弃 showtopic=1234 之后的任何内容,那么只需删除指示字符串结尾的 $
$2 implies there are two bracketed areas, but I only see one in your rule, so changed that to $1.
Also your URL starts /forum/ so need to include that in the rule.
And the . in index.php needs to be escaped if you don't want it treated as a regex special character.
And if you want to ditch anything after the showtopic=1234 then just remove the $ that indicates the end of the string