moebin
By:
moebin

404 redirect not working in htaccess - RewriteCond

July 1, 2015 1.7k views
WordPress Apache CentOS

Hey All,

I'm left scratching my head here, I have the following rule in my htaccess that is simply being ignored it would seem.

the idea is to redirect users coming in on older backlinks from:

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

to

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

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

Hi! Make sure .htaccess files are enabled and allowed to override settings. Edit the virtual host's config file and set AllowOverride to All and restart Apache.

If that doesn't work, please post the last few lines of Apache's error log:

sudo tail -30 /var/log/apache2/error.log

Ok AllowOverride is set to All (already) and I have tried a simple redirection and it works.

tail came up with the following, repeated lines so I pasted some as an example

[Thu Jul 09 10:23:17.711256 2015] [proxy_fcgi:error] [pid 12034] [client 10.132.65.228:36967] AH01071: Got error 'Primary script unknown\n'
[Thu Jul 09 10:23:25.637647 2015] [proxy_fcgi:error] [pid 12013] [client 10.132.65.228:36987] AH01071: Got error 'Primary script unknown\n'
[Thu Jul 09 10:23:50.170817 2015] [proxy_fcgi:error] [pid 12068] [client 10.132.65.228:37075] AH01071: Got error 'Primary script unknown\n'
[Thu Jul 09 10:24:05.804748 2015] [proxy_fcgi:error] [pid 12091] [client 10.132.65.228:37197] AH01071: Got error 'Primary script unknown\n'
[Thu Jul 09 10:24:23.446141 2015] [proxy_fcgi:error] [pid 12013] [client 10.132.65.228:37276] AH01071: Got error 'Primary script unknown\n'

Have another answer? Share your knowledge.