Forum Moderators: phranque

Message Too Old, No Replies

Please help!

         

bekyed

7:23 pm on May 2, 2004 (gmt 0)

10+ Year Member



I just successfully converted my site to PHP with dynamic includes. For whatever reason (SEO?), I would like my pages to appear static. And since we're at it, would it be harder to make them look like .html instead of .php?

Example URLs of my site would be:
[domain.com...]
[domain.com...]

I would like them to appear:
[domain.com...] (or .html)
[domain.com...]

But here's where my bi-directional question comes in: Is it possible to use mod-rewrite to have my links within my document appear as:
<a href="home.php">home</a>
instead of current:
<a href="index.php?page=home">home</a>

Or, because of the $_GET'[page] factor in PHP is that not possible? Here's my PHP dynamic page code if that helps:
<?php
if(isset($_GET['page'])) {
include("{$page}/index.php");
print($page);
}
else {include('home/index.php');
}
?>
Would this need to be changed to accomplish what I'm trying to do?

BTW, I tried tackling this myself but didn't get very far. Because each page variable changes, I got confused:
RewriteEngine on
RewriteRule ^index\.php$ newlink.php [R=301,L]

Bek

WhosAWhata

8:44 pm on May 2, 2004 (gmt 0)

10+ Year Member



you can't change anything in you scripts(like making?page=home look like home.html)

the mod_rewrite code would look like this


RewriteEngine on
RewriteRule ^(.*).html$ index.php?page=$1 [R]

hope this helps
if the user accesses
home.html they get sent to index.php?page=home
about.html they get sent to index.php?page=about

jdMorgan

10:13 pm on May 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



bekyed,

The basic approach is to "manually" change the links on your pages to "friendly" format. Do this in your script that produces the pages. This friendly format is then what users and SE spiders will see when they fetch the pages, bookmark them, link to them, and list them in search results.

Then on the front end of requests to your server, use mod_rewrite in .htaccess or in httpd.conf to grab the requested URL, and change it back to the format that your script needs. With a small but important change, that's what the code posted above does:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)\.html$ index.php?page=$1 [L]

You don't want to use an [R] flag, because that invokes an external redirect, which defeats the purpose of using friendly URLs.

Jim

WhosAWhata

4:37 am on May 3, 2004 (gmt 0)

10+ Year Member



sorry about that, i always get [R] and [L] mixed up

CNibbana

2:50 pm on May 3, 2004 (gmt 0)

10+ Year Member



Why does this question by bek look exactly like the same question I asked several days ago? I mean word for word:

[webmasterworld.com...]