|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
URL rewriting (?)
Hello,
To make my upcoming website seo friendly I want to implement some URL rewriting (I guess, if someone knows a better solution to the following please let me know). The website is a webshop with a lot of different products. The website is in php so normally I would write my product pages something like this: mysitedotcom/product.php?ID=100&Categorie=Hat&Subcategorie=Red%20Hat&Name=Superflex%20Red%20Hat All the information for the different Categorie, Subcategorie and Name would be pulled from a MYSQL database. What I want to do is make the URL like this: mysitedotcom/Hat/Red-Hat/Superflex-Red-Hat.html So what I need is: - PHP must become .HTML - Database fields must be used to make a "tree" in the URL (--> /.../...) - ID should not be visible because this doesn't say anything about the product - I want "- " implemented for spaces so that the internet explorer doen't give the standard "%20" How do I do this? Also, I do not want to link from one page to "mysitedotcom/product.php?ID=100&Categorie=Hat&Subcategorie=Red%20Hat&Name=Superflex%20Red%20Hat" where it rewrites to "mysitedotcom/Hat/Red-Hat/Superflex-Red-Hat.html" on that page. In fact, I don't want this contruction (mysitedotcom/product.php?ID=100&Categorie=Hat&Subcategorie=Red%20Hat&Name=Superflex%20Red%20Hat) visible anywhere in my website code for Google to see. How do I pull this off and can this be done using Dreamweaver. I guess this is quite a request, if u need more info, please let me know. I do know a website who does this very well (www dot klara dot nl !!! not so suitable for work however) They do this in not only their productpages, but also their category and subcategory pages, which is exactly what I want to do. Many thanks in advance! |
|
#2
|
||||
|
||||
|
Here is a useful toolto help you http://www.seochat.com/seo-tools/url-rewriting/
|
|
#3
|
||||
|
||||
|
This will require "alot" a work most likely, and require editing of your webshops backend. Here is an idea, you should search your webshops website to see if any mods\addons exist already to create SEO friendly URLs, if not you might want to hire a freelance to do this work for you, I highly doubt anyone will go beyond linking you to apache url modding resources.
|
|
#4
|
|||
|
|||
|
Quote:
The thing is that this website still needs to be build and I want to do it right the first time. So, I can really still do anything.... I'll have a look around, but if anyone here has some experience or really solid suggestions I would love to hear them. kind regards. |
|
#5
|
||||
|
||||
|
Quote:
I would take a look at ZenCart and OSCommerce then for your backend. |
|
#6
|
|||
|
|||
|
depending on what software you use for your website, i would suggest looking for any SEO plugins. most major php software suites have SEO modifications or plugins. doing this task yourself is daunting.
|
|
#7
|
|||
|
|||
|
Quote:
I agree, I have thought about the things I would need to do to implement this troughout the site. The problem of rewriting the URL for product pages does not seem to be the biggest problem, however, I also want to link directly to the correct link obviously (so this isn't rewriting anymore is it?) and how on earth do websites like i mentioned get the right data for their product page? I always used a GET method where the product ID was in the URL, but this isn't possible using link building like this... If anyone has experience making these websites and can tell me what the best software is for doing this job (prefferebly free software as I do not have a large amount of money to invest) please let me know. If you could also tell me how the mechanics of websites like www dot klara dot nl work (NSFW!) (Sorry, is one of the only websites I know who really did the job well implementing good links) please let me know, I am VERY interested of implementing this idea the correct way when I start! Thanks. |
|
#8
|
||||
|
||||
|
What you are talking about depends on what is the platform of your server. If you are using php it is most likely Apache (linux). If so, then you would use mod_rewrite. I was in the same situation for a IIS (windows) server and there are products for that that are different. Find out some info on your server first and post back.
__________________
A sig test: castrol srf | Graphical Force "When everybody is special . . . nobody will be." -Syndrome |
|
#9
|
|||
|
|||
|
Quote:
I am currently looking for a linux based server. However, I am very flexible on this one because I have worked on both in the past for small webshops. (So if windows is easier I could look at that as well..) |
|
#10
|
|||
|
|||
|
Quote:
Hi, Thanks for the tool, it seems quite handy, but doesn't this leave me with a lot of problems? For instance, when I link page 1 to the dynamic page, doesnt the original link still apply on page 1? So wouldn't this be the case: on page 1 this link: mysite dot com/product.php?id=1&name=Example would link to the rewritten dynamic page mysite dot com/product/ID/1/Name/Example/ ???? If the 'linking URL' in the code would also be converted then this would help a lot. |
|
#11
|
||||
|
||||
|
Quote:
I would suggest using 301 redirects on your original URL's to your new URL's. |
|
#12
|
|||
|
|||
|
Hello Joppiesaus,
There is 2 way for URL Rewriting. One is to using POST on the place of GET. And another is by Apache URL Rewriting. you can see it on this location: httpddotapachedotorgslashdocsslash1dot3slashmiscsl ashrewriteguidedothtml |
|
#13
|
||||
|
||||
|
Implementing mod_rewrite in the manner you've suggested is involved, but taken step by step it shouldn't be that daunting.
First thing is to take a look at the .htaccess rules, eg. Code:
RewriteRule ^/(.*)/(.*)/(.*)\.html$ /product.php?Categorie=$1&Subcategorie=$2&Name=$3 Here you can see that we pass 3 variables, split by forward slashes, to the script: Categorie, Subcategorie, and Name. As you've already mentioned, the ID variable is no longer present, so that rules out the ability to fetch the required product from the database according to its ID number. Instead you need to look at what other variable you can use. In the case above that would be Name. It's still not ideal though, as in a larger shop there's plenty of opportunity to have more than one product with the same name. Secondly, you'd need to replace hyphens with spaces via php before calling the database, but what if the product name has hyphens in it? Too much possibility for error for my liking. What to do then? My personal preference would be to introduce a new variable: Slug. This would be stored as a seperate, indexed column in the database, and would equate to the pseudo filename, avoiding any escaped characters. In your example URL ( /Hat/Red-Hat/Superflex-Red-Hat.html ), Slug would be "Superflex-Red-Hat". So, instead of searching the database for $_GET['ID'], you'd be searching for $_GET['Slug'] (sanitizing the input of course). The .htaccess code would then be something like: Code:
RewriteRule ^/(.*)/(.*)/(.*)\.html$ /product.php?Categorie=$1&Subcategorie=$2&Slug=$3 Constructing the URL The next step would be to create a function to construct the URL to maintain consistancy, eg So, in product category lists for example: 301 redirects You also need to ensure that the old style URLs are no longer available. The easiest way is to check for the value of $_SERVER['REQUEST_URI'] If a '?' is present it's an old style one, and so retrieve the data, pass it through the writeUrl() function, and redirect. By checking for old-style URLs it does at least mean that missing a hard-coded URL somewhere in your site isn't going to lead to duplicate pages. I would also implement a check for the categories. If you happen to move the product to a different category, the URL would still work if you were just searching the database for $_GET['Slug']. Perhaps even consider removing the categories from the URL altogether. That way it may be possible to remove some database requests for category data just to construct the URL (speeding up the site), and should you decide to change categories you don't have to change the URL as well (providing long term URL stability). Without seeing the existing code for your site I can't really be any more precise, but it should at least give you some food for thought.
__________________
... I'll be back for breakfast
New to SEO? SEOChat SEO FAQsForum Rules and Posting Guidelines URL canonicalization code solutions Vigorously pursuing the floccinaucinihilipilification of cheap SEO tricks
|
|
#14
|
|||
|
|||
|
Absolutely great how you are able to make this clear to me, a marketing dude with only some basic knowledge on php and very very basic knowledge on mod rewriting. You have my thanks!
1: The .htaccess line seems very logical. You "rename" the variables into variable $1 etc so they are easy to work with. 2: If I understand you correctly, the slug varibale has to be added manually in the database for each product that is added? So I manually will add hyphens to the product name if necessary and no errors can occur because it is manually added and it does not need to be rewritten in any way (comparable to the ID variable, only the slug variable says something about the product which is better for SEO reasons)...? constructing the URL 3.a: I am not exacly sure what this php function does (this has to be implemented on every page in the website right? (or at least included via a different 'functions page'?)), but i guess it just builds up the URL when the 3 variables are found in a dynamic URL. 3.b: does this php code also take into account that when there is no third variable that only the first two need to be used, and when there is only a first variale that only one should be used? Example: mysite.com/product.php?Categorie=Hats&Subcategorie=Red-Hats would be rewritten in "mysite.com/Hats/Red-Hats/" and not "mysite.com/Hats/Red-Hats/ /", because if that is the case, should I also link to my category which are not dynamic pages like this to make sure everything is consistent? 3.c: shouldn't there be a http://mysitedotcom somewhere in the code (I once read that it was better to link with absolute links, cant remember why dough 4. Could you explain what this line of code does exactly: [PHPNET] while ($f = $res->FetchRow()) { echo '<a href="' . writeUrl($f['slug'],$cat,$subCat) .'">' . $f['product_name'] . '</a>'; }[/PHPNET] I think that it can be used to link to the product page with the product name, but what does "while ($f = $res->FetchRow()) " do and shouldn't the slug, cat and subcat be in a different order? I'm sure they dont, but im still a noob so im trying to understand what this line does... 301 redirect 5: Smart of ya to think ahead of old style URL's which might slip trough If a '?' is present it's an old style one, and so retrieve the data, pass it through the writeUrl() function, and redirect." is a bit to fast for me, how exactly would I do this? 6: The check for categories used to be a big problem for me as well. For instance: mysitedotcom/product?ID=1&Category=hat&name=super-hat would also be found when just using product.php?ID=1, because the GET only needed the ID variable. This ment that when a category changed Google wouldnt drop the old URL because the page could be found using the right ID and the old category names. I never got a category check working, but if someone would link externally to mysitedotcom/hat/red-hats/super-hat/ and the category would change to green hat: mysitedotcom/hat/green-hats/super-hat/ , could the product then still be found because it automatically knows that the third "/" contains the slug variable? 7: I could indeed "hard code" the category and subcategorie from the category pages, e.g.: mysitedotcom/product.php?Category=Hat&Subcategory=Red-Hat&Name="variable URI"/. Is this what you meant? Anyways, thanks a million for your clear explenation! Nick Quote:
|
|
#15
|
||||||||
|
||||||||
|
2) The "Slug" variable. Yes you can either manually add it to the database via phpMyAdmin, or create a new field in the admin form that adds products to the database, or have the script create it automatically from the product title. My preference would be the second option, as that would be the most convenient, and give me more control than the 3rd option.
3a) The function is simply a convenient way of constructing the URL. You could do without, but then it would result in more php code every time the script had to output a URL. Functions like these help reduce the number of lines of code, and help maintain consistency. 3b & c) You'd need to adjust the writeURL() function slightly, to account for the possibility of an empty slug variable. No reason why you couldn't add the full domain path into the function, or through a definition eg: php Code:
4) This just serves as an example of looping through the products on a category page, outputting the link to individual products. I've used $f=$res->FetchRow() because I've been using database wrappers for too long and I can't for the life of me remember what the mysql php code is! As for the order of the three variables, you can put them in any order you like provided that they correspond to the order they appear in the function. If you changed it to cat,subcat,slug then you'd need to do the same for the function itself. 5) $_SERVER['REQUEST_URI'] is a global variable that returns the full path to the page minus the domain, eg: www.domain.com/Hat/Red-Hat/Linux.html $_SERVER['REQUEST-URI'] would be: /Hat/Red-Hat/Linux.html Thus, if you wanted to check for the presence of '?' in the URL: php Code:
As always, there's various ways of achieving the same result using other $_SERVER variable, but that's my preferred. 6) Yes, if the database is queried only for the "Slug" variable, then it doesn't matter to the script what you put in the categories, hence my suggestion for checking that they are correct. Without the check someone could maliciously link to your site using the URL /teens/xxx/super-hat.html and it'd still work. Not what you'd want appearing in the search results!! To perform the check you just need to pull the category information from the database for the product (don't know how the database tables are set up so can't really give any example code here), compile the URL as if you were creating a link, then check that against what is actually in the browser address bar. If they don't match, then again perform a 301 redirect. 7) My reference to "hard coding" simply means putting links in pages without constructing the URL dynamically, for example if you had a blog post and wanted to link to the product from there, you'd type in the URL just as you would if you were linking to an external site. You'd want to use the new style URLs though, rather than the old ones with a query string. |
![]() |
| Viewing: SEO Chat Forums > Google > Google Optimization > URL rewriting (?) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|