简体   繁体   English

RedirectMatch在.htaccess中不起作用

[英]RedirectMatch not working in .htaccess

I'm using 我正在使用

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

to try and 尝试和

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

What am I missing? 我想念什么?

I'm using centos 7, latest httpd from yum 我正在使用centos 7,来自yum的最新httpd

adding a bit more details 添加更多细节

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

need to 301 redirect to 需要301重定向到

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

my htaccess 我的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>

END WordPress 结束WordPress

As I commented above, you cannot match query string using RedirectMatch . 正如我上面评论的那样,您无法使用RedirectMatch匹配查询字符串。 Use mod_rewrite rule instead like this: 像这样使用mod_rewrite规则:

RewriteEngine On

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM