Welcome to WebmasterWorld Guest from 107.22.24.16

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Quick little RewriteCond Problem. Halfway there!

Need some help over here.

     
5:58 pm on Jul 7, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 25, 2008
posts:88
votes: 0


the URL in the search engines shows:

[somecompany.org...]
I want it to go to
[somecompany.org...]


RewriteCond %{HTTP_HOST} ^somecompany.org
RewriteCond %{QUERY_STRING} ^p=insurance$
RewriteRule ^index\.htm$ [somecompany.org...] [R=301,L]


I have like 20 pages just like that. Any Ideas? Ive read a bunch of tutorials and can't find one sniplet.
6:16 pm on July 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


That's the redirect for AFTER you have changed the links on the page to point to the new URL. URLs are defined in links. You change a URL by changing the link the user clicks on.

You have the redirect from query string URL to SEF URL in place. Next you need a rewrite to accept SEF requests and rewrite the request to the script to return the content.

Once both are in place you'll find you have an infinite redirect-rewrite loop. Change the RewriteCond in the redirect code to look at THE_REQUEST and not QUERY_STRING. This will ensure you redirect only direct client requests, not previously rewritten pointers.

Use the Live HTTP Headers extension for Firefox to investigate the HTTP transaction between browser and server.
7:09 pm on July 7, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 25, 2008
posts:88
votes: 0


Yea i have all of the links working and they have double indexed.
I have rewritten the index page so have the right links there and click. However the damage is already done. Some with the ?p= and some with the .html are in google.

So im trying to avoid all of the duplicate content issues.

I even tried:
RewriteBase /
RewriteRule ^?p=insurance$ [somesite.org...] [R=301,NC,L]
8:11 pm on July 7, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


RewriteRule cannot see query strings, as mentioned above. You need a preceding RewriteCond looking at THE_REQUEST.

Add a question mark to the end of the target URL to stop the query string data being re-appended.

Use example.com in the forum to stop URL auto-linking. [google.com...]
8:08 pm on July 20, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:Aug 25, 2008
posts:88
votes: 0


So proud of myself. I finally figured it out thanks to your THE_REQUEST tip.

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?p=([^&]+)\ HTTP/
RewriteRule ^$ [example[dot]com...] [R=301,L]

Worked like a charm. Any Other tips maybe?
10:22 pm on July 20, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Yes, make sure that index.php as well as blank is also redirected.

Use
/(index\.php)?\?p
and
^(index\.php)?$


Use example.com in the forum to stop URL auto-linking.