Welcome to WebmasterWorld Guest from 54.226.194.180

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess how to 301 these situations.

     

jmdb71

8:56 pm on Oct 27, 2005 (gmt 0)

10+ Year Member



Hi,
I have a couple situations i was needing help with. my site home page is indexed in the searches like so:

www.mysite.com/

however, im getting duplicates of my index page from referrals, such as:
www.mysite.com/?source=granitecitytool
www.mysite.com/?referral=whoever

I would like to 301 redirect any request for www.mydomain.com/?(whatever here) to www.mydomain.com to avoid these duplicates. i am terrible with htaccess and need some help with this.

my other similar situation is i have a couple pages indexed twice, like

www.mysite.com/page1.html AND
www.mysite.com/page1.html?=

How could i make any page that ends in?= redirect permanently to the same url without the?=

thank you so much in advance!

jd01

10:25 am on Oct 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You will need to use a QUERY_STRING condition for Apache to 'see' the information after the question mark, then append a blank QUERY_STRING on the rewrite.

Like this:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) http://www.example.com/$1? [R=301,L]

I also recommend visiting the Apache Library [webmasterworld.com] and Forum Charter [webmasterworld.com] for more information on mod_rewrite.

Hope this helps.

Justin

jmdb71

2:00 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



thank you so much. that solves my first problem. im still stuck on how to code my second situation:

a permanent redirect for any page ending in?= back to the page without that extension, for example

www.mysite.com/page1.html?= permanently redirected to:
www.mysite.com/page1.html

any help GREATLY appreciated!

jmdb71

4:23 pm on Oct 28, 2005 (gmt 0)

10+ Year Member



im so close..

i used the code above:

RewriteCond %{QUERY_STRING} .
RewriteRule (.*) http://www.example.com/$1? [R=301,L]

and it was interfering with my cod to tranform dynamic into static pages. however, it would work IF it identified only pages that end in?= and not any query on the end. how could i modify this for that condition only, so it wouldnt change pages for example ending in .html?product=12, but only .html?=.

thanks in advance!

Note: this did solve my referral problem above, and would work for that if the above code was only limited to the domain with any query at the end, but not any page within the domain..

jdMorgan

1:30 am on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



how could i modify this for that condition only, so it wouldnt change pages for example ending in .html?product=12, but only ".html?="?

RewriteCond %{QUERY_STRING} ^=$
RewriteRule ^(.+\.html)$ http://www.example.com/$1? [R=301,L]

this did solve my referral problem above, and would work for that if the above code was only limited to the domain with any query at the end, but not any page within the domain.

You can pretty much do whatever you want with rewrites, but you must very precisely define the problem first -- Which kinds of URLs you do you want to rewrite, and which ones you don't. So are you looking for a second rule in addition to the modified one above?

...limited to the domain with any query at the end, but not any page within the domain.

RewriteCond %{QUERY_STRING} .
RewriteRule ^$ http://www.example.com/? [R=301,L]

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

jd01

2:46 am on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You might also look at removing all query_strings from original requests, but allow them on rewrites...

RewriteCond %{THE_REQUEST} \?.*\ HTTP/ [NC]
RewriteRule (.*) http://www.example.com/$1? [R=301,L]

I use this on most of my dynamic sites, so helpful webmasters cannot create new pages for me...

EG

/page.php?OK=1&to-duplicate-content-I'll-add-another-parameter-and-link-it=hosed

You could probably adjust the Rule/Cond for efficiency.

Justin

jdMorgan

3:53 am on Oct 29, 2005 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



...adjust the Cond for efficiency:

RewriteCond %{THE_REQUEST} \?[^\ ]*\ HTTP/

Spaces, if present in the query string, would be escaped, so testing for not-a-space is safe -- and faster than using an embedded ".*" regex.

...continuing my anti-dot-star crusade... :)

Jim

jmdb71

2:54 pm on Oct 31, 2005 (gmt 0)

10+ Year Member



thank you both so much. this code worked like a charm, and was VERY helpful!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month