0

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:

  1. 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]

  2. 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]

  3. Thank you!

Edit 2: Not working above because conflict. More accurate solution goes to this topic .htaccess friendly URl

1

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you. The site goes to the right url but I get 404 Not Found. I need something like url rewrite or user friendly url. RewriteEngine is turn on also the module. Examples for pages, <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?a=page&b=([^&\ ]+) RewriteRule ^ /page/%1? [R=301,L] </IfModule>
@napsters if http://www.mydomain.com/profile/john doesn't exist, why in the world would you be redirecting google to those URLs?
I want trim the URL, It's something like using htaccess files for pretty URLS. Working url would be like this mydomain.com/index.php?a=profile&u=john and want to change it like OP above.
Ok I got it working using two method by Dan Trimper and you. Thanks!
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.