【问题标题】:Redirect issue with .htaccess file.htaccess 文件的重定向问题
【发布时间】:2014-10-10 19:44:55
【问题描述】:

我正在尝试在我的 .htaccess 文件中添加重定向,但我正在努力处理 URL 中的 + 标志。

这是我在.htaccess 文件中的重定向条目

Redirect 301 "^http://www.emfs.info/glossary/glossary+c.htm$" "http://www.emfs.info/glossary-2/"

任何帮助都会很棒。

【问题讨论】:

  • 加号被解析为正则表达式“关键字”,必须用 `` 转义
  • 感谢您的意见

标签: .htaccess url-rewriting url-redirection


【解决方案1】:
  1. Redirect directive 不接受正则表达式模式。
  2. 模式不需要用引号括起来。
  3. 如果所有规则都针对同一个主机 emfs.info,那么您不需要使用整个 URL 结构。
  4. 确保正在加载mod_alias

试试RedirectMatch:

RedirectMatch permanent /?glossary/glossary+c.htm$ /glossary-2/

将其放入文档根目录的.htaccess 文件中。如果您想要使用mod_rewrite 的其他方法,请尝试以下操作:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} www\.emfs\.info$
RewriteRule ^/?glossary/glossary\+c.htm$ /glossary-2/ [R=301,L]

把这个放在htaccess文件的同一位置。

【讨论】:

  • 感谢您,非常感谢!我设法找到了一个 WP 插件来操作 URLS 中的 + 符号。不过,我也要试一试。不错!
猜你喜欢
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多