Reputation: 657
I have a problem whereby google has indexed some pages with the wrong url.
The url they are indexing is:
1. http://www.mydomain.com/index.php?a=profile&u=john
2. http://www.mydomain.com/index.php?a=page&b=about
3. http://www.mydomain.com/index.php?a=settings&b=avatar
4. http://www.mydomain.com/index.php?a=feed
5. http://www.mydomain.com/index.php?a=feed&filter=picture
6. http://www.mydomain.com/index.php?a=post&m=32
7. http://www.mydomain.com/index.php?lang=english
8. http://www.mydomain.com/index.php?a=messages&u=john&id=4
9. http://www.mydomain.com/index.php?a=feed&logout=1
I need it to redirect to:
1. http://www.mydomain.com/john or http://www.mydomain.com/profile/john
2. http://www.mydomain.com/about or http://www.mydomain.com/page/about
3. http://www.mydomain.com/settings/avatar
4. http://www.mydomain.com/feed
5. http://www.mydomain.com/feed/picture or http://www.mydomain.com/feed/filter/picture
6. http://www.mydomain.com/message/32
7. http://www.mydomain.com/lang/english
8. http://www.mydomain.com/messages/john
9. http://www.mydomain.com/logout or http://www.mydomain.com/feed/logout
.htaccess isn't my forte, so any help would be much appreciated.
Thanks in advance.
Edit:
Ok, I got it working by using two method by Dan Trimper and Jon Lin. First I'm generate mod rewrite url by using Dan Trimper method. For example http://www.mydomain.com/index.php?a=page&b=about
, so after generate it will produce the url like this RewriteRule ^([^/]*)/([^/]*)$ /index.php?a=$1&b=$2 [L]
Second, after generate I'm using second method redirect url to http://www.mydomain.com/page/about
by using Jon Lin method:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\?a=page&b=([^&\ ]+) RewriteRule ^ /page/%1? [L,R=301]
Thank you!
Edit 2: Not working above because conflict. More accurate solution goes to this topic .htaccess friendly URl
Upvotes: 0
Views: 910
Reputation: 86
I wasn't too savvy with .htaccess when i first started too.
Check out this site along with the .htaccess generator - It helped me out ALOT and i think it will fix your issues.
http://www.generateit.net/mod-rewrite/
It pre-writes the rules for your after you configure it - then copy/paste to your .htaccess file.
Upvotes: 1
Reputation: 143886
Try adding these rules to your htaccess file in your document root:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=profile&u=([^&\ ]+)
RewriteRule ^ /profile/%1? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=page&b=([^&\ ]+)
RewriteRule ^ /page/%1? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=settings&b=([^&\ ]+)
RewriteRule ^ /settings/%1? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&logout=1
RewriteRule ^ /feed/logout? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
RewriteRule ^ /feed/%1? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed
RewriteRule ^ /feed/? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=feed&filter=([^&\ ]+)
RewriteRule ^ /feed/%1? [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=post&m=([^&\ ]+)
RewriteRule ^ /message/%1? [L,R=301]
etc.etc.
Upvotes: 1