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

  • jpietrowiak
  • Born
  • Born
  • jpietrowiak
  • Posts: 3

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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.
  • jpietrowiak
  • Born
  • Born
  • jpietrowiak
  • Posts: 3

Post 3+ Months Ago

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
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

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.
  • jpietrowiak
  • Born
  • Born
  • jpietrowiak
  • Posts: 3

Post 3+ Months Ago

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
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

Certainly.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 47 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.