-1

I am trying to build a "standard" website in which the path to articles have SEO friendly URL Something like this:

www.test.com/library/book-34/chatper-4/page-10/

The website is build with PHP and mySQL. In this example we access the content of a page from a given chapter of an e-book. As for reasons which can easily be found on the web, I'd like to use this form rather than:

www.test.com/library.php?book=34&chap=4&page=10

I made some research on the web and found this link for instance: SEO friendly url using php

I like the idea of using FallbackResource as suggested in this post, and I tried however, while I don't understand the mechanism fully, I came to the conclusion that it only works if the file we want to access in the URL is not on the file system. So if you type www.test.com/test/toto and that the file toto doesn't exist then yow will be redirected to whatever FallbackResource points to. The problem with this approach is that it doesn't seem to work for paths such as:

www.test.com/folder/folder-1/folder-2

Because it seems like this considered as a series of sub-directories rather than a missing file. So I get an Error 500 in that case when FallbackResource is used (I can't really explain whether this is the right reason, but this is the only one I could come up with on my own. I asked on Stackoverflow but no answer so far: FallbackResource works for some pages but not others).

What I need is to "decompose" the URL so that I can look at the right information in the database. For example find the id of the book 34, and find in the database a page 10 which belongs to chapter 4 of book 34. I know how to do that. I can also build the URL.

What I don't know, is what's the best way to actually redirect any URL such as www.test.com/f-1/AA/B-2/tmp/C04/ or whatever, to a page from which I can then use the url path to extract the data from the database and display it on the page?

It seems like using a mechanism to catch missing pages (404) is not a good approach. I am also aware of the possibility of using RewriteRule but it seems like FallbackResource was said to be a better choice. However I can't get it to work in a generic fashion (maybe someone can tell me how, or what I am doing wrong?).

CMS are using SEO friendly URLs all the time, so there must be a "standard" way of doing this, and one that works in all cases (not like FallbackResource which seems limited).

It's the only part of my project which is not working yet, and because of this I am stuck while being close to the result. It's very frustrating. Any help would be greatly appreciated.

Community
  • 1
  • 1
user18490
  • 3,546
  • 4
  • 33
  • 52
  • 3
    I have yet to see any evidence that one url will rank above the other in any search engine –  Aug 13 '14 at 21:41
  • Have you looked into .htaccess and mod_rewrite? - and + to dagon. It's foolish to assume search giants like google are in any way thwarted by the structure of the URL. It's the page content that matters most – Kai Qing Aug 13 '14 at 21:42
  • What do you mean? That there is no for FallbackResource to work for www.test.com/test/tmp-1 but not www.test.com/test/tmp-1/tmp2? That's what I would thought but that's exactly what I see and explained in my other post. – user18490 Aug 13 '14 at 21:43
  • @Kay: I don't understand. I guess I can use RewriteRules if that's the way to go. I am just asking what's the best most reliable way standard way of doing this? I don't understand what the content has to do with it. I just want to know how to use SEO friendly url and how redirect them to a page from the information can be exracted from the db and displayed on the page. – user18490 Aug 13 '14 at 21:47
  • @Mario. I don't understand your comment which doesn't seem constructive. Either people can help the OP or they can't. The post have 2 different topics. One is to understand better how FallbackRessource works, and the other how generally the SEO friendly URL approach works and is dealt with with .htaccess and PHP. Thank you. – user18490 Aug 13 '14 at 21:49
  • 1
    mod_rewrite is pretty standard, but it is not the only way that is considered standard. You can use mod_rewrite to rewrite every URL to a single file that uses something like parse_url() to extract the needed information, as opposed to setting up a rewrite rule for every path. I am not sure about the fallback suggestion because I have never needed to do something like that. It sounds like a solution for a static site, in my opinion, and I would sway away from that unless you have a very good reason to do that. I work in a web firm. We use htaccess minimally to write to a common parser file. – Kai Qing Aug 13 '14 at 21:51
  • [Edited] I read your other question. Almost similar, it ask for different topics – Federico J. Aug 13 '14 at 21:52
  • 1
    And the content I refer to is stating that your URL can be as ugly as possible, but if the content on that page of your site is relevant, properly constructed and doesn't appear to employ any black hat techniques, it is highly unlikely that the "friendliness" of a URL is impacting your search placement in any way. Most humans don't really look at a URL beyond "https" if buying something. Other than that, we typically don't care what the URL says, so your only reason for doing it the pretty way is to conform to a common assumption, or the mild appeasement of a client who knows no better – Kai Qing Aug 13 '14 at 21:54
  • @Kai: thank you for developing. It's well explained, and informative. The is what I like about SOverFlow, not the negativity. – user18490 Aug 13 '14 at 21:57

2 Answers2

1

I don't think google will care much about what you have past .com/ but your users will. It is much easier for them to understand and looks better so I think it is worth doing.

Apache ModRewrite is the way to go.

Enigma Plus
  • 1,519
  • 22
  • 33
0

I think that if you read this article, http://symfony.com/doc/current/book/http_fundamentals.html, specially the part "The Journey from the Request to the Response > The Front Controller" you may grab the idea of how to implement it.

Briefly, you send all server request to an index.php file which will parse the request and send them for the appropiate file. You'll need to configure your apache server an .htaccess (you need redirect module from apache active) that will redirect all the traffic there.

You won't have any trouble with pages that exist or not, as you won't hit them directly, just through your front controller.

Federico J.
  • 15,388
  • 6
  • 32
  • 51
  • This is a common standard. Typically mod_rewrite is enabled by default on most server services you may use. godaddy, dreamhost, mediatemple, etc. – Kai Qing Aug 13 '14 at 21:56
  • I activated it (mod_rewrite) and learned about it as well. But if you look at the first link I added in the post, one person answered that FallbackResource was the way CMS were doing it. So started with this, based on this advise but don't truly understand the scope of what it can do. – user18490 Aug 13 '14 at 22:02
  • I didn't know about FallbackResource, I'll check it. But with the Front Controller you'll manage all your urls with regexp or strpos easily – Federico J. Aug 13 '14 at 22:25