Welcome to WebmasterWorld Guest from 18.207.238.169

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Redirecting PHP pages to html

Using .htaccess

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

New User

10+ Year Member

joined:Feb 17, 2005
posts:28
votes: 0


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]

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

New User

10+ Year Member

joined:Feb 17, 2005
posts:28
votes: 0


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]

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members