Forum Moderators: phranque

Message Too Old, No Replies

.htaccess Redirect Without thread or Post ID

         

brc2

12:50 am on Dec 16, 2005 (gmt 0)

10+ Year Member



I changed domain names approx. 6 months ago. Since that time I have been using the following .htaccess file to redirect traffic from my old domain to my new one. Since site switched software and old domain links would not take you to the correct place, I directed all traffic to my home page.

Current .htaccess for xyz.com
RewriteEngine ON
RewriteRule (.*) [abc.com...] [R=301,L]

The .htaccess file works, but it is creating a lot of duplicate links in the search engines by appending the thread or post idea to the redirect. For example...

Old domain Google link...
www.xyz.com/phpbb/viewtopic.php?p=1399

New domain Google link...
www.abc.com/?p=1399

I would like to have the redirect remove the appended thread and post ideas so those indexes would eventually be removed.

Thanks,
B

jdMorgan

1:04 am on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



B,

Add a trailing question mark to clear the current query_string:


RewriteEngine on
RewriteRule (.*) http://www.example.co[b]m/?[/b] [R=301,L]

This "?" character *will not* appear in the new URL; it simply forces the query string to be removed.

Jim

brc2

2:22 am on Dec 16, 2005 (gmt 0)

10+ Year Member



Thanks Jim! I works great!

Is there a way to rewrite existing indexed pages likes this (abc.com = new domain name)? These links appear before the links with new content.

www.abc.com/?p=1399

to

www.abc.com

Thanks again for your help!
B

jdMorgan

2:44 am on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I understand your question, you need to *redirect* them, not rewrite them.

See the 4th rule in message #2 of this recent thread [webmasterworld.com]. You'll need to modify the query string test to only look for blank vs. non-blank (a regex pattern of "." will suffice) and change the URLs, of course, but the basic idea is what's needed.

Jim

brc2

3:17 am on Dec 16, 2005 (gmt 0)

10+ Year Member



Thanks again Jim! However, that last rule might be out of my grasp. To make sure we are on the same page...

New domain links in the search engines that were indexed as a result of the rewrite appear as...
www.abc.com/?p=1399
or
www.abc.com/?t=412
etc...

I want to help get these out of the search engines so I want to redirect these links to www.abc.com. Now for the rule you referenced. I'm not sure where to begin but here is my attempt.

# Externally redirect direct client requests for dynamic URLs to new-style static URLs
# (in case your dynamic URLs accidentally get exposed to the search engines)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ \.php\?c=([^&]+)&d=([^&\ ]+)\ HTTP/
RewriteRule ^\.php$ [abc.com...] [R=301,L]

I'm really confused, lol. Do I have to add this info to the .htaccess as well?

#An example of {THE_REQUEST} would be:
GET /mytown/index.php?c=widgets&d=14 HTTP/1.1

Thanks for your help and patience!
B

jdMorgan

4:19 am on Dec 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The correct code depends on *exactly* what you're trying to do, and typed words sometimes fail to describe the situation completely, but here's my take on it based on your posts in this thread:

# Externally redirect direct client requests for "/" with "p=" or "t=" querystrings to the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?[pt]=[^\ ]*\ HTTP/
RewriteRule ^$ http://www.example.com/? [R=301,L]

This may be too specific, in that it only redirects requests as you've shown them: a request for the home page with a query string of "p=<anything>" or "t=<anything>". I try to err toward being very specific rather than insufficiently-specific, since the side effects of not being specific enough are poor server performance and (possibly) redirecting or rewriting URLs that you don't intend to rewrite.

Jim

brc2

4:41 am on Dec 16, 2005 (gmt 0)

10+ Year Member



Jim,
Thank you VERY much for your help! The code you provided works great! My main concern was as you stated...with "p=<anything>" or "t=<anything>".

It appears to be functioning correctly with my existing rewrite...

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^newdomain.com [NC]
RewriteRule ^(.*)$ [newdomain.com...] [L,R=301]

# Externally redirect direct client requests for "/" with "p=" or "t=" querystrings to the home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /\?[pt]=[^\ ]*\ HTTP/
RewriteRule ^$ [newdomain.com...] [R=301,L]

Due to the 301 redirect I setup when I changed domains, Google has indexed thousands of pages from my site that originally appeared as...
www.oldomain.com/phpbb/viewtopic.php?p=1399

now appear as...
www.newdomain.com/?p=1399

So I have thousands of indexed pages all going to the same place and the idexes that point to 'new' content are buried. Hopefully this will help clean up my indexed pages in the search engines.

Thank