Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Rewriting "?" At Beginning of URL



12:54 pm on Mar 13, 2007 (gmt 0)

10+ Year Member

I'm at my wit's end with this one, and I've searched everywhere without help. Google has indexed my home page as:


and I want to redirect this to:


I'm not even sure how it grabbed this URL so I'm hoping to rewrite *any* numerical variable (i.e.?cat=[0-9])

The actual "home page" file is index.php if that is a factor.

Thanks in advance for any suggestions!


2:35 pm on Mar 13, 2007 (gmt 0)

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

I'm not sure whether you want/need to drop the query strings from index.php as well, so here are two rules, preceded by the required "setup":
Options +FollowSymLinks -MultiViews
RewriteEngine on
# Remove any query string from "/"
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ http://www.example.com? [R=301,L]

# Remove any query string from "/" or "index.php"
RewriteCond %{QUERY_STRING} .
RewriteRule ^(index\.php)?$ http://www.example.com? [R=301,L]

If you have other working rewriterules, then you may not need the "setup" stuff. However, if you don't have a working knowledge of mod_rewrite, I strongly suggest you review the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com] before trying to use this code.



5:27 pm on Mar 13, 2007 (gmt 0)

10+ Year Member

The first example worked fine, thanks!

Featured Threads

Hot Threads This Week

Hot Threads This Month