homepage Welcome to WebmasterWorld Guest from 54.167.41.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess how to 301 these situations.
jmdb71




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

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




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

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




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

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




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

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




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

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




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

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




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

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




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

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

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