views:

156

answers:

3

Hello folks,

I recently turned an old Joomla site into a Wordpress site and I want to redirect the old urls to the correct new ones. For starters I tried to redirect them all to the homepage but even that didnt work.

All the old urls look like website.com/?q=node/1 (or sometimes ?q=user/ etc), so I figured this would be enough:

RewriteCond %{QUERY_STRING} ^q=(.*)

RewriteRule . /home/ [R=301]

Why doesn't this work?

A: 

Have you enabled the rewrite engine? You need to enable it in httpd.conf AND in all virtual hosts, since directives are not inherited. Reference: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteEngine

RewriteEngine On

RewriteCond %{QUERY_STRING} ^q=(.*)

RewriteRule . /home/ [R=301]
PatrikAkerstrand
I have, and after this rule there's some wordpress rules that are working fine. Sorry if I was incomplete in my question.
Litso
+2  A: 

[EDIT - FINAL SOLUTION - see comments]

RewriteCond %{QUERY_STRING} q=
RewriteRule (.*) lexlijst.nl/$1? [L,R=301]
Josh
if I would do that I don't think the rules after that will have any effect, making wordpress unable to show any page except the front page ;)
Litso
no it is conditioned to the line before i.e. your querystring
Josh
try just putting RewriteCond %{QUERY_STRING} q= as the condition to remove the querystring
Josh
see http://www.dranger.com/weblog/entry/apache_mod_rewrite_strip_query_string.html
Josh
hmm, did you add that later or did I just look over that in the first place? Anyway, same as spliff's answer, it gives a 301 document stating it was moved to the exact same url as was enterd
Litso
just edited my answer - see if that helps
Josh
whoa, I overlooked something in the link you gave Josh. It seems to work fine now, thanks a bunch!
Litso
cool - what was the final solution?
Josh
(for future reference and stuff, the correct rule was:RewriteCond %{QUERY_STRING} q=RewriteRule (.*) http://www.lexlijst.nl/$1? [L,R=301]as stated by that article on dranger.com)
Litso
A: 

You can debug this sort of thing by adding a RewriteLog line. I suspect your RewriteRule line is the culprit though. It should be something like:

 RewriteRule .* /home/ [R=301]
SpliFF
hmm, without the log but with the asterisk added at least I get a response from the server: a 301 document stating the page moved to the exact same URL as was initially entered (so still with the ?q= unfortunately):http://www.lexlijst.nl/?q=node/1
Litso