Reputation: 9293
I'm creating a simple, wordpresslike cms and keep all parts of a page in a table and load them using a template page named view.php
following by a $_GET variable, for example:
sky.com/view.php?article=how-to-do-something
But as I can see on wordpress sites there is no 'view.php' template file and $_GET
variables inside url. There is pure domain name and title of an article.
I suppose this is a better approach for SEO engines.
What is the general way to do this and how can I use the same. Is there a function to create a file on fly, or maybe a hidden file system...
The same is with stackoverflow.com
. There is no view template inside url, but I'm rather sure it uses database table for storing parts of a page.
I tried with .htaccess file and this accepted solution but got the error 500 - internal server error.
Upvotes: 0
Views: 39
Reputation: 22760
By way of explanation; what stackoverflow.com
probably does is something like this:
URL:
https://stackoverflow.com/questions/44654672/cms-without-view-template-inside-url
Actual URL is first rewritten using mod_rewrite
so that 1) the missing .php
is added, and 2) the GET parameters are set:
RewriteEngine on
RewriteBase /
RewriteRule ^questions/([0-9]+) questions.php?qid=$1 [NC,L]
And so the questions.php
page loads the question with id 44654672.
The above mod_rewrite says: take the URL, starting with questions/
and send that URL to questions.php
, as well as saying: After questions/ take the number value and use that as the question id GET variable so that the PHP page loads the correct question from the database.
The wording in the URL is purely for SEO purposes.
You will notice that https://stackoverflow.com/questions/44654672
will also load your question correctly (*), but if you change the number value (even while keeping the words the same, ( such as https://stackoverflow.com/questions/44351172/cms-without-view-template-inside-url ) another question will be loaded from the database.
Think of it as the mod_rewrite
is doing a find and replace search on the URL string. That's all.
Upvotes: 1