Click here to Skip to main content
15,886,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, I’m using php/mysql on Windows shared hosting and have 1000 individual items to display on 1000 versions of the dynamically generated detail page which currently shows, for example, as: http://www.mydomain.com/folder/detail.php?ID=3 (http://www.mydomain.com/folder/detail.php?ID=3) The problem is the very unfriendly search engine and user experience regarding the ’folder/detail.php?ID=3’ part of the url. I want to display item 3 as a permalink, for example, http://www.mydomain.com/the-compleat-angler-book (http://www.mydomain.com/the-compleat-angler-book). An added problem is that some of the items are duplicates but all have different listed because they are secondhand and therefore has different characteristics (price, condition). But each has a unique ID so that could be includes in the url string /568-the compleat-angler-book and /778-the compleat-angler-book for example.
I’ve been looking at url rewriting, web.config, and htaccess for new to all of them. (Happy to move the hosting to Linux if that made this issue easier to accomplish.) Can anyone suggest the best way forward here? Any comments appreciated. Thanks.

What I have tried:

Research only - nothing physical just yet because I'm not sure what to do.
Posted
Updated 22-Feb-23 23:15pm
Comments
Richard MacCutchan 21-Feb-23 6:50am    
It is not clear where you asre putting these URLs, but in a web page they should be displayed in <a></a> pairs. And if so you can put any user friendly text there.
Richard Deeming 21-Feb-23 8:01am    
If you're worried about search engines, then you need to pay attention to spelling.

It's "complete", not "compleat".

And I'm suspicious that you didn't mean "angler" (someone who catches fish), but "Angular" (a Javascript programming framework).

Mistakes like that will probably have more of an impact on your site's ranking than dynamic URLs.
Member 13934081 21-Feb-23 13:46pm    
Thank you Richard MacCutchan - I'm thinking I'll have to put them in the database. Say the product title was 'The Compleat Angler', another field could hold the desired url reference such as the-compleat-angler and another the unique record reference. But not clear on your point about pairs. Each of my products - even if they had the same url reference in the db would have a unique url because I could concatenate the unique reference with the url reference in order to to produce something such as http://www.mydomain.com/568-the-compleat-angler-book. Does that make sense?
Member 13934081 21-Feb-23 13:46pm    
Thank you Richard Deeming and ouch! The project doesn't actually involve books but my use of the compleat angler was used to illustrate my problem. (I think you'll find that The Compleat Angler is an early spelling (and the one I prefer to use) of a well known title (see https://en.wikipedia.org/wiki/The_Compleat_Angler). Any thoughts regarding how I might resolve the question very much appreciated.
Richard Deeming 23-Feb-23 5:22am    
I'm assuming that's "well known" in certain circles, which I'm obviously not part of! :D

That does illustrate another SEO problem though: which spelling to use when there are multiple candidates. The Wikipedia article says both "compleat" and "complete" are used, even in the first edition of the book. So it depends which version you think more people will be searching for, and whether the search engine will try to "correct" the spelling for them.

You might be tempted to have a friendly URL for both spellings pointing to the same book. But in that case, Google will punish you for having duplicate content on multiple URLs. If you went down that route, you'd need to have one version issue a redirect to the other, or use a canonical link element[^] to tell Google what the preferred version was.

1 solution

You can use URL rewriting techniques to convert the dynamic URLs into static URLs by changing it'd format.

In your .htaccess file you can use something like this -
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ detail.php?url=$1 [L,QSA]


You can then parse the URL and retrieve the required data from the database -
// Get the requested URL
$url = $_GET['url'];
//In your case  - http://www.mydomain.com/folder/detail.php

// Parse the URL to get the article ID
$parts = explode('/', $url);
$article_id = $parts[1];
//ID = 3

// Query the database for the article with the specified ID
$stmt = $pdo->prepare('SELECT * FROM articles WHERE id = :id');
$stmt->execute(['id' => $article_id]);
$article = $stmt->fetch();

// Display the article
echo '<h1>' . $article['title'] . '</h1>';
echo '<p>' . $article['content'] . '</p>';
 
Share this answer
 
v2
Comments
Member 13934081 24-Feb-23 10:33am    
Thanks Andre. I new to this so bear with me... the second stage is what I'm doing anyway - grabbing the ID from the url and from it retrieving and displaying the correct product for the page. So how is the rewrite stuff knowing what to say in the 'new' url? (i.e. mydomain.com/detail.php/name-of-my-product rather than mydomain.com/detail.php?ID=3 And what happens when someone save the page -presumably as /name-of-my-product and tries to go back to it? (Presumably, it only works one way? - enter the ?ID=3 version and it can turn it into /my-nice-page but enter my-nice-page from scratch and it's going to be a 'page not found'? And if so that suggests 1000 static pages?)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900