Forum Moderators: phranque

Message Too Old, No Replies

301 redirects for Joomla non sef urls not working

         

RamZ

11:27 pm on Sep 3, 2012 (gmt 0)

10+ Year Member



Im trying to redirect non sef urls already bookmarked by google to the new sef urls but am having trouble doing so.

I have included the following in my htaccess but it isnt working.

Redirect 301 /?option=com_sobi2&catid=2&Itemid=28 /http://example.com/
Redirect 301 /?option=com_sobi2&catid=6&Itemid=64 /http://example.com/sporting


Can anyone please tell me how I can redirect these links to the new sef urls so I can correct the links in google.

phranque

11:51 pm on Sep 3, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



welcome to WebmasterWorld, Ramz!

the Redirect directive uses mod-alias and you want to use mod_rewrite instead.
you can look for patterns in query strings using the RewriteCond directive.

RamZ

12:29 am on Sep 4, 2012 (gmt 0)

10+ Year Member



Could you explain this in a little more detail please or give me an example on how to achieve this?

g1smd

4:48 am on Sep 4, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use a RewriteRule for each path and a preceding RewriteCond looking at QUERY_STRING for each query string. There's several thousand prior threads with example code.

Make sure you get the latest htaccess file from the Joomla site, even if you are not upgrading Joomla to the latest version.

Make sure the new code goes in the right place in the file. Hint: it does NOT go at the beginning or the end.

phranque

7:30 am on Sep 4, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



here are a few examples.

site:webmasterworld.com RewriteRule RewriteCond QUERY_STRING:
http://www.google.com/search?num=100&q=site%3Awebmasterworld.com%20RewriteRule%20RewriteCond%20QUERY_STRING%20 [google.com]

RamZ

1:33 am on Sep 5, 2012 (gmt 0)

10+ Year Member



Thanks.

Got it sorted using the following, in the right place.

RewriteCond %{QUERY_STRING} ^option=com_sobi2&catid=8&Itemid=66$ [NC]
RewriteRule ^index\.php$ /lifestyle/? [R=301,NE,NC,L]

phranque

2:06 am on Sep 5, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i would be cautious when using the NC flags.
the only time i typically use an NC flag is when the pattern is testing the hostname.
the rest of the url should properly be case-sensitive, or you are asking for canonicalization problems.

lucy24

9:07 am on Sep 5, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you need NE for? There aren't any fancy characters in the rewr, er, redir...

OUCH!

If you're redirecting, you need the complete protocol and domain

http://www.example.com

so everyone ends up on the same page, with no stray port numbers and no random www's floating around. But the good news is that this makes [NC] OK, because you want to grab everyone and send them to the canonical form of the name.

People who ask for index.php by name would need to be redirected anyway. But what about the ones who ask for your domain in its proper form? That's either ^$ or !. in htaccess (both mean "the null request"). Do they get a separate rule? Easiest approach is to say simply

^(index\.php)?$