Forum Moderators: phranque

Message Too Old, No Replies

Redirecting PHP pages to html

Using .htaccess

         

mickapoo

2:26 am on Feb 17, 2005 (gmt 0)

10+ Year Member



We have redone our site converting from php to html. I now would like to create redirects so the cached pages are redirected to the html pages.

For example, www.example.com/home.php?cat=62

Redirecting to this:
[example.com...]

I tried regular redirect 301, but it didn't work. I also tried a few other methods, but probably had the syntax wrong. Can anyone assist me in what is the proper procedure?

Thank you.

[edited by: rogerd at 6:51 pm (utc) on Feb. 17, 2005]
[edit reason] Please use example.com for all URL illustrations [/edit]

jdMorgan

3:00 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



mickapoo,

Welcome to WebmasterWorld!

This recent thread [webmasterworld.com] and the references cited in our forum Charter [webmasterworld.com] will help you get started.

Jim

mickapoo

1:19 pm on Feb 17, 2005 (gmt 0)

10+ Year Member



I tried this:
RewriteEngine On
RewriteRule /home\.php\?cat=62 http://www.example.com/Sample-Packages-c-62.html [R=301]

and also

RewriteEngine On
RewriteRule ^whatever\/whatever\.php\?a=11$ http://www.example.com/newfile.html [R=301,L]

but nothing worked.

[edited by: jdMorgan at 4:13 pm (utc) on Feb. 17, 2005]
[edit reason] Removed specifics per TOS. [/edit]

jdMorgan

4:15 pm on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, read carefully in claus' post about catching the query string.

A query string is not part of a URL. Rather, it is data to be passed to a resource (script) at that URL. So, RewriteRule cannot 'see' the query string, and you must use RewriteCond to test it.

For example:


RewriteCond %{QUERY_STRING} ^cat=([0-9]+)
RewriteRule /home\.php$ http://www.example.com/Sample-Packages-c-[b]%1[/b].html [R=301,L]

This will 'copy' the value of the cat= numeric parameter from the query string into the new URL.

Note that you may need to preface this code with

 Options +FollowSymLinks 

on some servers in order for mod_rewrite to run. Otherwise, you'll get a 500-Server Error, and a message in your server error log telling you to enable SymLinks. This depends on the httpd.conf configuration.

Jim