如何从字符串之间删除问号

huangapple go评论55阅读模式
英文:

How to Remove Question Mark from between the strings

问题

我尝试了很多方法,但没有帮助。

已经尝试了
RewriteRule ^string?string$ /string [L,R=301]
但没有帮助。

英文:

Somehow Google indexed one of the pages as
domain.com/string?string
How can I rewrite it to
domain.com/string
So, need to remove ?string from the url.
Tried many ways but didn't help.

Thank you in advance.

Already tried
RewriteRule ^string?string$ /string [L,R=301]
but it did not help.

答案1

得分: 1

抱歉,我只能为您提供翻译服务。以下是您提供的内容的翻译:

无法使用 RewriteRule 匹配查询字符串的部分。这一点在文档中已经明确说明,并且在SO上已经有无数现有的答案中展示过。

相反,您需要使用 RewriteCond 并明确删除查询字符串:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^string$
RewriteRule ^/?string/?$ /string [QSD,L,R=301]

通常,您应该在中央HTTP服务器的主机配置中实施此类规则。如果您无法访问该配置(也就是说,如果您正在使用廉价的托管提供商),则可以使用分布式配置文件(通常命名为".htaccess"),前提是通常启用了此类文件的解释,并且已配置了在此类文件中覆盖规则的选项(请参阅文档中的AllowOverride 指令)。

此外,您应该考虑为什么谷歌能够对这样的URL进行编目。这意味着机器人在某处找到了指向该URL的链接。您也应该解决这个问题。虽然您仍然需要实施重定向以防止得分扣除,但当然您也希望修复原因,而不仅仅处理症状。

英文:

You cannot match parts of the query string with a RewriteRule. That is clearly documented. And shown in an endless number of existing answers here on SO.

Instead you need the assistance of a RewriteCond and explicitly delete the query string:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^string$
RewriteRule ^/?string/?$ /string [QSD,L,R=301]

In general you should implement such rules in the central http server's host configuration. If you do not have access to that (read: if you are using a cheap hosting provider) you can instead use a distributed configuration file (often named ".htaccess"), if the interpretation of such files in enabled in general and if you configured the option to overwrite rules in such files (see the AllowOverride directive in the documentation).

In addition you should consider why Google has been able to catalog such a URL. That means that the robot found a link to that URL somewhere. That is what you should take care of too. You still have to implement the redirection to prevent a scoring penalty, but certainly you want to fix the cause, not just handle the symptom.

答案2

得分: 0

这将从URL中移除任何 ?string

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ $1? [R,L]
英文:

This will remove any ?string from URL

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+)$
RewriteRule ^(.*)$ $1? [R,L]

huangapple
  • 本文由 发表于 2023年4月17日 00:08:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028883.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定