Forum Moderators: phranque

Message Too Old, No Replies

Need to convert php to html

         

texanweb

12:53 am on Apr 23, 2006 (gmt 0)

10+ Year Member



Ok I know to change one page ext. to another page ext is to do this:
Options +FollowSymLinks
RewriteEngine on

RedirectMatch 301 (.*)\.php$ http://www.example.com$1.html

However I want to change all strings like this:
www.example.com/links/add.php?cat=42&ma=1
www.example.com/links/add.php?cat=44&ma=1
www.example.com/links/add.php?cat=53&ma=1

to turn in to this:
www.example.com/links/add/cat/42.html
www.example.com/links/add/cat/44.html
www.example.com/links/add/cat/53.html

How can I do that? I don't have any codes!

jdMorgan

2:07 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This recent thread [webmasterworld.com] should go a long way toward getting you started.

Jim

texanweb

2:54 am on Apr 23, 2006 (gmt 0)

10+ Year Member



Ok what am I doing wrong.

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /add\.php\?links=([^&]+)&add=([^&]+)&cat=([^&]+)&num=([^&]+)\ HTTP/
RewriteRule ^add\.php$ http://www.example.com/links/%1/%2/%3/[R=301,L]

[edited by: texanweb at 3:08 am (utc) on April 23, 2006]

jdMorgan

3:03 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Missing space before [R=301,L]?

Also "&num=([^&]+)\ HTTP/" should be

&num=([^\ ]+)\ HTTP/

Jim

texanweb

3:14 am on Apr 23, 2006 (gmt 0)

10+ Year Member



You know, I think its me. I just cant get mod rewrite to work for me.
Here is my code again:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /add\.php\?links=([^&]+)&add=([^&]+)&cat=([^&]+)&num=([^\ ]+)\ HTTP/
RewriteRule ^browse\.php$ http://www.example.com/links/%1/%2/%3/ [R=301,L]

Just wondering, where is it telling the browser to convert it to .html?

jdMorgan

3:21 am on Apr 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not telling the browser to convert anything. It's redirecting browser requests for the dynamic page URL to a static page URL.

I think the post I cited above covered this subject fairly thoroughly... If you want to change the links you publish, change your pages. Then use mod-rewrite to convert the URLs in those links, when requested from your server, back into the form needed to run your script.

Jim

kunaal84

4:01 am on Apr 24, 2006 (gmt 0)

10+ Year Member



Hi,
I've tried applying those methods and it all worked fine except for one thing, when the php file's been redirected to a html the values that were sent with the html are transfered too:

Eg. www.host.com/index.php?user=1
after mod rewrite, whixh looks like this:
Options +FollowSymLinks
RewriteEngine On

# Internally rewrite search engine friendly static URL to dynamic filepath and query
RewriteRule ^(.*)/index.html sitemap.php?num=$2&page=$1 [L,NC]

# Externally redirect client requests for old dynamic URLs to equivalent new static URLs
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.php\?user=([^\]+)\ HTTP/
RewriteRule ^index.php$ [%{HTTP_HOST}...] [R=301,L]

I get www.host.com/1/index.html?user=1

The problem is I want to get rid of the value and I have no idea where it is getting it from if i specifically redirect to index.html?

Thanks for your help,
Solitary

jdMorgan

4:08 am on Apr 24, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Stick a question mark on the end on the substitution URL:

RewriteRule ^index.php$ http://%{HTTP_HOST}/%1/index.ht[b]ml?[/b] [R=301,L]

That will clear the query string.

Jim

kunaal84

4:47 am on Apr 24, 2006 (gmt 0)

10+ Year Member



Thanks a lot, that did the trick.

:) :D