RedirectMatch not working in .htaccess

949 views Asked by At

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

adding a bit more details

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

need to 301 redirect to

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

my 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

1

There are 1 answers

12
anubhava On

As I commented above, you cannot match query string using RedirectMatch. Use mod_rewrite rule instead like this:

RewriteEngine On

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