【问题标题】:Remove string from URL using .htaccees [closed]使用 .htaccess 从 URL 中删除字符串 [关闭]
【发布时间】:2013-04-16 22:07:18
【问题描述】:

我已经建立了一个 bit.ly 链接并将其打印在 1000 个传单上。 不知何故,bit.ly 目标链接包含一些不应该存在的字符串(https://example.com/page/%E2%80%8E 而不是https://example.com/page/

我可以使用.htaccess 中的重写规则来摆脱这个字符串吗?

感谢任何帮助!

【问题讨论】:

  • 给出一些重定向 URL 的示例以及重定向 URL 重定向的原始 URL。

标签: string .htaccess url mod-rewrite bit.ly


【解决方案1】:

当您在创建短链接时不小心添加了字符串%20%E2%80%8E,那么您可以直接获取另一个短链接,而不会再次添加字符串。

无论如何,我认为这些.htaccess 指令是你想要的:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1 [R,L]

它将example.com/$anything%20%E2%80%8E重定向到example.com/$anything

只需确保您的网络托管帐户上有带有mod_rewrite 的 Apache HTTP Server。并考虑了有关[R=301] 标志的链接:https://stackoverflow.com/a/15999177/2007055


这段代码:

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)/\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1/ [R,L]

是将example.com/$anything/%20%E2%80%8E重定向到example.com/$anything/

【讨论】:

  • @PhiLieb 请检查更新。
猜你喜欢
  • 1970-01-01
  • 2014-09-30
  • 1970-01-01
  • 2021-08-18
  • 1970-01-01
  • 2012-11-28
  • 2017-06-01
  • 2020-12-30
相关资源
最近更新 更多