Rewrite http://site.com/?************* to http://site.html

  • jpietrowiak
  • Born
  • Born
  • No Avatar
  • Joined: Mar 27, 2009
  • Posts: 3
  • Status: Offline

Post March 27th, 2009, 7:40 pm

Hi all,
I have been struggling with this to no avail. Should be simple but I need to redirect any page from site.com/?(with anything after it) to site.com. I made an accident rewriting from an old site to the new site and my ranking suffered dramatically since it shows so many duplicate home pages.

Redirect http://sub.site.com/(nothinghere)?(anything after here) to http://sub.site.com

So anotherwords
Redirect http://sub.site.com/?**** to http://sub.site.com
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post March 27th, 2009, 7:40 pm

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 27th, 2009, 7:49 pm

So you want to redirect anything pointing to the home page that uses a querystring, to the home page but without the querystring ?

Code: [ Select ]
RewriteEngine On

RewriteCond %{QUERY_STRING} !^$
RewriteRule ^/?$ http://sub.site.com/? [R=301]
  1. RewriteEngine On
  2. RewriteCond %{QUERY_STRING} !^$
  3. RewriteRule ^/?$ http://sub.site.com/? [R=301]


The ? must be present in the destination URL without a QSA flag so that Apache drops the querystring when redirecting. The [R=301] flag makes it work like "Redirect permenant ..." would.
Strong with this one, the sudo is.
  • jpietrowiak
  • Born
  • Born
  • No Avatar
  • Joined: Mar 27, 2009
  • Posts: 3
  • Status: Offline

Post March 28th, 2009, 3:21 pm

Thanks for the quiuck reply! I'm a newbie so here is something I got that seems to be working ok from this example someone else posted that I tried from another forum. Its a little different from what you posted but looks close. But I have no clue whats best or what some of this means. Or for that matter if it will affect the current links in Vbulletin. I have tested a little with the below and it seems ok though. Please let me know your thoughts. Thanks

Code: [ Select ]
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ http://sub.site.com/? [R=301,L]
  1. RewriteCond %{QUERY_STRING} .
  2. RewriteRule ^$ http://sub.site.com/? [R=301,L]
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 28th, 2009, 3:29 pm

The differences are trivial, they both essentually do the same thing.
It's a case of "you say potato I say potatoe".

In mine the code reads "if QUERY_STRING isn't empty"
In theirs it reads "if there's anything in QUERY_STRING"

In mine the pattern will tolerate a lone forward-slash
In theirs it doesn't

In mine the L (or last rule) flag is dropped because R=301 will automaticly cause the rewrite to return so L doesn't matter.
In theirs L is probably added out of habit.

You could flip a coin to decide which one you want to use unless you're using an older version of Apache where the tolerance of a single forward-slash may be needed.
Strong with this one, the sudo is.
  • jpietrowiak
  • Born
  • Born
  • No Avatar
  • Joined: Mar 27, 2009
  • Posts: 3
  • Status: Offline

Post March 28th, 2009, 3:43 pm

Ok so it sounds like they both do basically the same thing. The forward slash sounds to be the most compatible then so I think I will go with that then. Thanks for all your input. Have a great weekend.
  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post March 28th, 2009, 3:48 pm

Certainly.
Strong with this one, the sudo is.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 149 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.