homepage Welcome to WebmasterWorld Guest from 54.211.180.175
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Quick little RewriteCond Problem. Halfway there!
Need some help over here.
acimag




msg:4336512
 5:58 pm on Jul 7, 2011 (gmt 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.

 

g1smd




msg:4336523
 6:16 pm on Jul 7, 2011 (gmt 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.

acimag




msg:4336551
 7:09 pm on Jul 7, 2011 (gmt 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]

g1smd




msg:4336588
 8:11 pm on Jul 7, 2011 (gmt 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...]

acimag




msg:4341912
 8:08 pm on Jul 20, 2011 (gmt 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?

g1smd




msg:4341981
 10:22 pm on Jul 20, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved