3
votes

I got this Joomla problem - google seems to have indexed a menu entry of mine which i had removed, but i forgot to remove the entry in the menu so now google have indexed this site:

http://www.madplanuge.dk/?Itemid=134

I wan to redirect it (.htaccess) to this url: http://www.madplanuge.dk/madplan/lav-madplan

How would you do that. i have already tried following:

RewriteRule ^\?Itemid=134 http://www.madplanuge.dk/madplan/lav-madplan? [R=301,L]

RewriteCond %{REQUEST_URI} ^\?Itemid=134$
RewriteRule ^\?Itemid=134$ http://www.madplanuge.dk/madplan/lav-madplan? [R=301,L]

Neither of the above solutions worked.

2

2 Answers

4
votes

You can't do it with a RewriteRule alone because Apache will ignore the query string. Here I'm doing the redirect if the query string contains the ID we're looking for.

RewriteCond %{QUERY_STRING} Itemid=134 [NC]
RewriteRule ^.*$ http://%{HTTP_HOST}/madplan/lav-madplan? [R=301,L]

Remember when you're testing that your browser will cache your 301 redirect, so you'll need to clear your cache to see any changes.

1
votes

You're doing 2 things wrong:

  • The %{REQUEST_URI} always begins with a slash, so the RewriteCond needs ^/\? instead of ^\?

  • Change the ^\?Itemid=134$ in the RewriteRule to ^.*$. The RewriteRule takes the entire URL as the first argument, not just the Request URI.

More information on Apache rewrites can be found here.