Forum Moderators: phranque
We have a customized oscommerce website. There are SEO friendly URLs but they only work for products. I'd like to create SEO friendly URLs to other links too. Can someone guide me how to do this using the .htaccess file or otherwise.
1.
Eg.
On our website
http://www.example.com/product_info.php?products_id=11387
will convert to
http://www.example.com/thermal-transfer-paper-labels-datamax-desktop-printers-p-11387.html
But from the Manufactures page
http://www.example.com/manufacturers.php
The manufacturers links display as follows
http://www.example.com/manufacturers.php?manufacturers_id=34
How do I convert
manufacturers.php?manufacturers_id=34 to the Manufacturer name
as an example I'd like the link to be displayed as follows
http://www.example.com/datamax-m-34.html
Can some one help?
2.
http://www.example.com/product_info.php?products_id=11387
Even though the above URL converts to SEO friendly URL
http://www.example.com/thermal-transfer-paper-labels-datamax-desktop-printers-p-11387.html
on some pages it doesn't convert to the SEO friendly URL.
Can some one please explain why and how we can resolve this matter.
Many Thanks
Kind Regards
[edited by: jdMorgan at 2:16 pm (utc) on June 20, 2009]
[edit reason] example.com [/edit]
Mod_rewrite does not change links on pages, or change URLs displayed in the browser address bar. Only the script that produces your pages can do that.
So the procedure is to modify your script(s) to produce the desired URLs, and then use mod_rewrite to "re-connect" those modified URLs, when requested from your server by a client, back to the correct filepath on your server.
In other words, you edit your script to produce links to "example.com/datamax-m-34.html" instead of linking to "manufacturers.php?manufacturers_id=34" on your pages. So the URL seen by visitors and search engines is now "example.com/datamax-m-34.html"
But that URL will no longer resolve to an existing file on your server, so you use mod_rewrite to detect requests for that URL, and rewrite the internal server filepath to /manufacturers.php?manufacturers_id=34 so that the server can find the correct script file.
It should also be obvious that mod_rewrite cannot create the "datamax-m-" information out of thin air. The only reason this works is that mod_rewrite is actually removing that information from the URL to get the correct filepath, and only adding the static filepath info to the id number that it 'copied' from the requested URL.
See our Apache Forum Library for useful threads on this subject. Also see the resources cited in our Apache forum Charter.
Jim
Thank you very much for your quick response. This was really helpful and it cleared some points I didn't understand before. Could you please guide me how I can edit the script to create SEO Friendly links. Please accept my apologies if Im asking too much here. I have no clue as I'm new to PHP and OSCommerce. So your advices and comments would be much appriciated. Many Thanks.
This routine (or these routines) will need to be modified -- either to re-format the link URLs derived from the database, or to reference a new field in the database which contains the new "friendly" URL.
If the database does not include the friendly URL, if the database cannot be easily modified, or if you do not wish to modify it, then you will need to use the preg_replace PHP function (and/or or similar) to modify the linked URL.
This response is necessarily general, as I am not familiar with your cart, and am not a PHP expert. If you do not have confidence in your ability to make these changes, then consider hiring a consultant who can do this work for you.
And regardless of whether you do the work yourself or hire it out, do remember to make a full backup of all of your scripts (and database, if modified) before work commences, and to make incremental backups as work proceeds...
Jim
Thanks so much for your reply. I've managed to re write the
http://www.example.com/manufacturers.php?manufacturers_id=34
to http://www.example.com/datamax-m-34.html
But the problem I have is
From the home page, categories page, manufacturers page, the link to a product shows as
http://www.example.com/thermal-transfer-paper-labels-datamax-desktop-printers-p-11387.html
but from some pages the link to the same product display as follows
http://www.example.com/product_info.php?products_id=11387
How do I fix this error? Because of this I have dupliacate URLs and redirect errors in Google Webmaster tools. Please let me know if you need our web address.
Many Thanks for your help
Kind Regards
[edited by: jdMorgan at 2:18 pm (utc) on June 20, 2009]
[edit reason] example.com [/edit]
Mod_rewrite can be used to 'connect' friendly URLs to script filepaths inside the server, and (after the fact) to clean up stale search results a bit faster and to recover traffic from old third-party links and old visitor bookmarks, but it cannot be used to "change URLs in the address bar."
Identify the script that produces the problematic pages, and look for and modify the "print the links on this page" routine, as before.
Jim