Forum Moderators: phranque

Message Too Old, No Replies

Trouble redirecting .php URL to .html in .htaccess

Why doesn't my current redirect 301 work for php URLs with variables?

         

CsectionRecovery

4:05 am on Jan 11, 2006 (gmt 0)

10+ Year Member



I know this should be simple and that I must be missing something basic.
I want to permanently redirect from
http://www.example.com/folder.php?id=1
to:
http://www.example.com/books.html

I tried this line in my .htaccess file:
redirect 301 /folder.php?id=1 http://www.example.com/books.html

but it just seems to ignore it. Other simple tests like this one work fine:
redirect 301 /123 http://www.example.com/books.html

Currently google has an assortment of php URLs indexed and cached - and I want to make sure it eventually crawls and caches my new .html versions of these pages so I can get rid of the dynamic .php version.

I did get one version of it working which redirected ALL urls which had /folder.php in it to the same final destination - but I want to ensure that the old Google indexed URL to my 'books' page for example will still go to my new static HTML 'books' page.

Thanks for tips, help or pointers to documentation.

Jeanne

[edited by: tedster at 4:15 am (utc) on Jan. 11, 2006]
[edit reason] use example.com in code [/edit]

jdMorgan

4:16 pm on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Jeanne,

Welcome to WebmasterWorld!

The Redirect family of directives in Apache mod_alias doesn't handle query strings. So you'll need to use mod_rewrite if your host allows you to do so:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=1$
RewriteRule ^folder\.php$ /books.html [L]

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