Hi David,
I was wondering if you could perhaps give me some pointers in making a page which has been parsed by Magic Parser search engine friendly.
In specific how to include a parsed "title" field into the title area of a page and also where to start with .htaccess URL rewrites.
I realise that this is potentially opening a can-o-worms for you but any direction would be grateful.
It is the site which I am trying to make SEO friendly Three Star Hotels
Thanks,
Simon.
Hi David,
Thanks for your quick reply.
I have done this code : -
RewriteEngine on
RewriteBase /
RewriteRule ^hotel_detail/(.*).html$ hotel_detail.php?hotel_id=$1&%{QUERY_STRING} [L]
Which should turn this URL
http://www.threestarhotels.co.uk/hotel_detail.php?hotel_id=75786
into this URL...
http://www.threestarhotels.co.uk/hotel_detail/75786.html
It doesn't seem to be working, what have I missed out?
Simon.
Hi Simon,
The rewrite seems to be in place, for example if you go to:
http://www.threestarhotels.co.uk/hotel_detail/75786.htmll
or
http://www.threestarhotels.co.uk/hotel_detaill/75786.html
...neither of which should work, you get an error - whereas:
http://www.threestarhotels.co.uk/hotel_detail/75786.html
works, so I think the problem is down to your script. In your script are you using $_GET["hotel_id"] to extract hotel_id from the URL?
One thing I always do in this situation is print_r($_GET) to in the rewritten script, for example:
hotel_detail.php:
<?php
print_r($_GET);
exit();
?>
Cheers,
David.
Hi David,
Yes I am using $_GET["hotel_id"] to extract hotel_id from the URL
What does that mean?
Simon
Hi Simon,
That expression means the hotel_id index of the $_GET superglobal. This is the array that is populated with the items that were on the URL, and is the best way to access variables provided to your script like this.
It looks like your rewrite is working fine, the problem is your main script. The following URLs display almost the same result:
http://www.threestarhotels.co.uk/hotel_detail.php?hotel_id=75786
and
http://www.threestarhotels.co.uk/hotel_detail/75786.html
The only difference I can see is that the logo is not displayed on the second one. This will be down to the fact that the image URL for your logo is relative, so when you are in the /hotel_detail/ virtual directory the path is wrong. To fix this, you need to specify an absolute URL for your image, for example src='/images/Gynogapod1d.gif'.
Hope this helps,
Cheers,
David.
Hi David,
I have now changed all the image URL's to absolute ones and that now seems to be sorted.
If the rewrite is working fine, why would it not be resolving when the page loads.
This is the script for the hotel_detail.php page
(copy saved)
Thanks,
Simon
Hi Simon,
I've saved a copy of your code, but it seems to be working ok now...
http://www.threestarhotels.co.uk/hotel_detail/75786.html
Apologies if i've misunderstood the question...
Cheers,
David.
Hi David,
I think we have crossed lines here :)
Before the URL rewrite the URL was
http://www.threestarhotels.co.uk/hotel_detail.php?hotel_id=2357
Surely when that URL is requested by the browser it will automatically rewrite it to...
http://www.threestarhotels.co.uk/hotel_detail/2357.html
which it isn't doing.
Have I missed the point of this?
Thanks,
Simon
Hi Simon,
It actually works the other way round. Having setup rewriting, there should never be any need to request the first URL. The "rewriting" means turning the search engine friendly URL into the original URL, so it is links to the new version that you want to construct throughout your website.
Are you in the situation where you have the old version in the search engines and you want to redirect them to new version?
This is the only reason why you would need to do this, otherwise if it is a new site simply never publish the first URL - always use the rewritten version...
Cheers,
David.
Hi David,
Well you learn something new everyday - I always thought it was the other way around!
It is a brand new site so ill construct the site as suggested.
Thanks again for all your help and patience!
Simon.
Hi David,
Cache has now been successfully (I think!) implemented. It is creating the files in the "cache" directory, but the page loads still seem to be very slow.
Is there a test I could perform to check if it is indeed working ok?
Thanks,
Simon.
Hi Simon,
Check what time value you are using compared to the period between requests. Are you using something like 86400 (1 day)?
Cheers,
David.
Hi Simon,
One way to check that the cache is being used is to:
1) Empty the cache directory
2) Request the page
3) Note the date/time on the cached file
4) Request the page
5) Compare the date/time on the cached file with that in step 3
Assuming that the date/time hasn't changed then you can be confident that the cache is working. If your server is on a particularly fast Internet connection then it is not impossible that generating the page is the slower part of the process, and so the difference may not be that noticeable.
Cheers,
David.
Hi Simon,
There is a basic method you can follow which makes this quite easy. What you want to do is layout your script so that all the main processing goes on at the top, and then you create the HTML with elements containing the value of variables that have been set higher up the script. For example, see how the following script would set the title element based on the data from an XML document:
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
global $title;
$title = $record["HOTEL-NAME"];
}
MagicParser_parse("hotel.xml","myRecordHandler");
?>
<html>
<head>
<title><?php print $title; ?></title>
</head>
<body>
-- rest of page --
</body>
</html>
Regarding .htaccess rewrites, the basic process is to create rules that bring in a parameter from the URL into the script as a variable. For example, you might want map the following URL:
http://www.example.com/hotels/123.html
to something like:
hotels.php?id=123
You could do this with the following .htaccess code:
RewriteEngine On
RewriteBase /
RewriteRule ^hotels/(.*).html$ hotels.php?id=$1&%{QUERY_STRING} [L]
That's the basic idea!
Hope this helps,
Cheers,
David.