Friendly URL whose ID is the news headline [duplicate]

0

I'm trying to implement in the route system an alias I want, whether it's coming from the database. Let's imagine a news portal where in the table of the bd I have the table "noticias" where a url is loaded for each news so that the url gets something like " link ". What is the best way to do this ???

Instead of using the numeric ID, I would like to use the news headline only.

    
asked by anonymous 20.07.2017 / 11:02

1 answer

-2

The easiest way to follow in your case is to use url rewrite in the .htaccess file.

What is a .htaccess file?

.htaccess files are Apache access and configuration files, are files read by Apache every time you try to access a file that is inside a folder (or sub folders) where there is an .htaccess file. In this file we can create access blocking rules, redirects and URL rewrites.

Example

# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]

# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id=$1 [L]

To go deeper into the subject follow this step by step, it's very simple to implement! link

    
25.07.2017 / 05:47