【问题标题】:RedirectMatch not working in .htaccessRedirectMatch 在 .htaccess 中不起作用
【发布时间】:2015-06-18 06:45:02
【问题描述】:

我正在使用

RedirectMatch 301 ^story.php?id=(.*) http://domain.com/p=$1

试一试

301 redirect domain.com/story.php?id=xxxx to domain.com/p=xxxx

我错过了什么?

我正在使用 centos 7,来自 yum 的最新 httpd

添加更多细节

http://domain.com/story.php?id=449

需要301重定向到

http://domain.com/?p=449

我的 htaccess

RewriteEngine On
RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC]
RewriteRule ^story\.php$ /?p=%1? [L,NC,R=302]
RewriteBase /
Redirect 301 /forums http://domain.com
Options -Indexes
#RewriteEngine On
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/forums/(.*)$ /forums/$2 [R=301,L,QSA]
RewriteRule ^([a-z]{2}|zh-CN|zh-TW)/(.*)$ http://$1.domain.com/$2 [R=301,L,QSA]
RewriteRule ^(server-info|bb-server-status) - [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

结束 WordPress

【问题讨论】:

  • 您无法使用RedirectMatch 匹配查询字符串。请改用mod_rewrite

标签: regex apache redirect http-status-code-301


【解决方案1】:

正如我在上面评论的,您无法使用RedirectMatch 匹配查询字符串。像这样使用mod_rewrite 规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^id=([^&]+) [NC]
RewriteRule ^story\.php$ /?p=%1 [L,NC,R=302]

【讨论】:

  • 您使用的是 302 而不是 301?
  • 我没有在上面添加更准确的 url 示例以确保我提供所有可能的详细信息
  • 没有人可以帮助您仍然无法正常工作没有任何详细信息的类型 cmets。这是在我的 Apache 上有效且经过测试的规则。
  • 你说得对,我把它移到了我的 .htaccess 文件的顶部,并用目标字符串测试了一个 url,它没有重定向
  • 按指示张贴在上面
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-08
相关资源
最近更新 更多