Hi All
I'm trying to hack productlist.php so that I can create individual named pages e.g. sony-laptop.php that will display search results for a specific keyphrase, e.g. "sony laptop". I have run into a few technical difficulties, which I explain in detail at:
http://www.webref.eu/exact-keyphrase-match-shopwindow-page.php
... and I really would be most grateful to anyone who can help me out with any advice or suggestions.
Thanks
Chris :cool:
You dont need to "hack" (as you put it) productlist.php to do this, you would just use your .htaccess file and mod rewrite
(this is top of my head stuff btw, so you might need to play to get it working)
Say you want Blue Widgets displayed on www.yoursite.com/blue-widgets.html (http://www.yoursite.com/blue-widgets.html)
you would use this command in your .htaccess:
RewriteRule ^blue-widgets\.html$ /productlist.php?q=blue widgets [L]
Obviously, you wont want a new line for every possible searchterm, so you would do:
RewriteRule ^([^/]+)\.html$ /productlist.php?q=$1 [L]
that way you could have purple-widgets.html displaying Purple Widgets, or green-fungus.html displaying Green Fungus etc etc
Those commands do not work entirely alone, you need to first turn the rewrite engine on so at the top of you .htaccess you'd have:
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
and then just put all your rewrite commands beneath.
I wouldn't use a .php as your rewritten url because if you did this:
RewriteRule ^([^/]+)\.php$ /productlist.php?q=$1 [L]
you risk sending the server into an infinite loop. Can you see why? Everytime it looks up productlist.php, it'll assume it doesn't exist and is rewritten. This is why you see so many .html pages online, they rarely are .html and are usually rewritten .php pages.
Anyway, onwards:
Once you have that working, it's just a case of changing the link url's that the php files output to reflect your new url format. That's the tricky bit. If you can get to that part let us know and we'll talk you through the rest if we can.
I am of course, assuming you're using a Linux server with permissions to alter .htaccess. If you're on windows, you've s**t out Im afraid
Thanks very much for your reply Andy. Using mod rewrite is something that had occurred to me, my only concern being can I SEO a page that is being generated via mod rewrite.
I'm on shared linux hosting BTW.
I'm going to have a think about things and will give updates if I have them.
Thanks