Forum Moderators: phranque

Message Too Old, No Replies

301 dynamic pages

how to redirect all possible variables

         

wheelie34

10:18 am on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



So, one of my advertisers has closed their doors and now I need to permanently redirect all their widget pages to the main page of that folder, heres what I am trying to do.

I have one template page widget-detail.php which depending on the widget (?widget=234) how do I tell it to redirect with one line of code in my htaccess file?

redirect 301 /widgets/widget-detail.php http://www.example.com/widgets/

Thanks in advance

g1smd

10:34 am on Oct 2, 2007 (gmt 0)

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



What code have you tried, and what result did you get?

wheelie34

10:40 am on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for the reply g1smd

I tried the above line, but if the request has?widget=123 it redirects to the page wanted BUT keeps the?widget=123 in the URL.

How do I tell it no matter what the request, 301 to the widget folder /

jdMorgan

1:40 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do this with mod_rewrite, bit "one line of code" won't be enough unless you are already using mod_rewrite:

Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^widgets/widget-detail\.php$ http://www.example.com/widge[b]ts/?[/b] [R=301,L]

The "?" at the end of the substitution URL is an operator that clears the requested query string; It does not appear in the redirected-to URL itself.

The first line of code (Options) is optional; It may or may not be required, and it may or may not be allowed on your server. This depends on your server configuration, and the only way to find out is to test.

If you add more RewriteRules in the future, you do not need to repeat the first two lines.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

[edited by: jdMorgan at 1:41 pm (utc) on Oct. 2, 2007]

g1smd

1:45 pm on Oct 2, 2007 (gmt 0)

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



Ha. Beat me to it.

Mornin' jd!

wheelie34

2:42 pm on Oct 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks guys, seems to work.