Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch 301 ignore ?

         

xbigfootx

10:48 am on Sep 20, 2011 (gmt 0)

10+ Year Member



Recently migrated from blogger to wordpress. Have removed some content and want to redirect search engine results to my main page, so users don't get a 404 error.

example of old content

www.mysite.co.uk/pics/picture.jpg?test=y&anothertest=y

I want to redirect any requests to /pics/* to www.mysite.com

currently using the following in htaccess file

RedirectMatch 301 /pics/(.*) h ttp://www.mysite.co.uk

this works fine for something like

www.mysite.co.uk/pics/picture.jpg

but not for

www.mysite.co.uk/pics/picture.jpg?test=y&anothertest=y

I end up with the following page, resulting in a 404 error

www.mysite.co.uk/?test=y&anothertest=y


How do I stop the ? string from being used for this redirect?

g1smd

12:29 pm on Sep 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Do not use Redirect or RedirectMatch for any of the rules.

Use RewriteRule for all of the rules. RewriteRule sees only the path part of the request. You will need a preceding RewriteCond looking at QUERY_STRING.

Read recent threads. This question, or one very like it, has been asked on average every 2 to 3 days for the last 10 years (and sometimes 2 or 3 times per day).

xbigfootx

1:59 pm on Sep 20, 2011 (gmt 0)

10+ Year Member



thanks - found what I was looking for after reading previous responses.

g1smd

2:04 pm on Sep 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good stuff! My cut and paste button is wearing out. :)

Feel free to ask detailed questions about specific problems and example code.