Forum Moderators: phranque

Message Too Old, No Replies

Can I 301 a "?"; can I 301 with a wildcard

hataccess

         

steveb

2:58 am on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



example.com/?1
example.com/?2
example.com/?3
example.com/?4

None of these exist and never existed, but Google thinks they do.

RedirectMatch permanent ^/?1$ http://www.example.com/
doesn't work

RedirectMatch permanent ^/?1 http://www.example.com/
doesn't work

RedirectMatch permanent ^/?1$ http://www.example.com/page.html
doesn't work

RedirectMatch permanent ^/?1$ http://www.example.com/
does redirect http://www.example.com/1 to
http://www.example.com/ but not
http://www.example.com/$1

Question 1... can I redirect www.example.com/?1 to www.example.com/

Question 2.... can I use some sort of wildcard to redirect all www.example.com/?**** URLS that use a "?" to the root URL? If so, how? (And redirect only "?" URLS, leaving the rest of the domain like www.example.com/dir/ and www.example.com/page.html unaffacted.)

jdMorgan

3:31 am on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This code will strip query strings from requests from your home page and do a 301 redirect:

# Redirect home directoryindex page with any query string
# to home directoryindex page without query string
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} .
RewriteRule ^$ http://www.example.com/? [R=301,L]

The first two lines are optional. You may not need line #1 at all. Its presence (if not needed) or absence (if it is needed) may cause a server error. You won't need line #2 if you already have that directive ahead of other mod_rewrite code in your .htaccess file.

I'm not sure if you wanted to strip query strings from *all* pages - that was not clear. If so, change the above RewriteRule to:


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

Note that the "?" in both rules is a syntax element used to clear the query string. It *will not* appear in the redirected URL.

Jim

steveb

5:21 am on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks again. You da best.