Friendly URL's

If you go to this site you will see that the read more links are user-friendly.That is wordpress doing all the job there.

Since though I do not use Wpress I am trying to achieve the same end result.
So the question is from where to begin.
I know and have read about .htaccess and mod_rewrite but I do not know if this is the solution for this case.

Besides having a friendly URL like in the site you see another question is based on what info database queries will be performed.

So,from where do I start?

In essence…I want to find a way(if possible) that leads to I can use the ID and get the blog post from the DB.

There would need to be something in the url which uniquely identifies that blog entry. The title may identify it, but you would then need some kind of look-up to associate the title with the id.
Alternatively, you maybe could use the title as the key to pull the entry from the database.
I think the easiest way is to combine the title and id, something like that would give a more meaningful url which includes the title, but also includes the id for the purpose of pulling the data from the database.

You can use Altorouter in your project.
Basically it does what you want but you need to read through the docs a bit.

A Rewrite map should work as a look-up.

Ι am having difficulty understanding it how to use this AltoRouter.
For example here is the my implementation of the map method

$router->map( 'GET', 'http://localhost/Appointments/Frontend/blog_show.php', function() {
    require __DIR__ . '/views/home.php';

As far as I can understand if the browser points to ‘http://localhost/Appointments/Frontend/blog_show.php
a redirection will take place to vies/home.php.

This does not happen though in my case and I do not know if the code above indeed does that…I am not sure.

The code you see above is placed in blog_show.php

I use a Php Framework and the following .htaccess file which directs everything and nothing to index.php

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

All you have to do is parse the parameters :slight_smile:

for now I want to focus with the issue at hand…more specifically with the problem I describe at post 6.

Your idea is not bad…I am planning to do it though at a later stage.

First off did you read trough the docs ?
If so then you know a little bit how this router is supposed to work.

But to explain a bit more, You should do it like this :

$router->map( 'GET', '/THE-URL-YOU-WANT-TO-SEE', function() {
    require __DIR__ . '/Frontend/blog_show.php'; // File that you load in.

what do you mean when you say the url you want to see.
I am confused a little.

That function does the following :
You click on a link that sends you to the following url “http://localhost/THE-URL-YOU-WANT-TO-SEE”.
The router knows the link if you set it up and will show the file that it needs to show.

So the map function works like this :

    "url that you want to be able to use",
    "class#method", // incase you use autoloading.
    "route name"

Did you read through the docs and the closed issues on github ?
If not do that before you directly come back with a question.

Also the example shows how to use the router.

Check out the website to btw :
Best regards.

Ι tried what you describe above and still cannot make it work.Let me explain:
In blog_show.php I have this link

<a href="http://localhost/Appointments/Frontend/blog_show.php">test allrouter</a>

I have also this code in blog_show.php

$router->map( 'GET', '/', function() {//for all GET requests
    require __DIR__ . '/views/home.php';

From what I have understand when the link is clicked I should be redirected to blog_show.php.
This does not happen.

Surely I miss something…but what.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.