Friendly URL whose ID is the headline of the news

Asked

Viewed 608 times

0

I’m trying to implement in the routing system an alias I want, coming from the database. Let’s imagine a news portal where in the table of the comic I have the table "news" where a url is loaded for each news for the url to look something like "http://www.omeusite.com/o-titulo-da-minha-noticia/". What’s the best way to do that???

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

  • You want to know "what’s the best way to do that" or "how to do this"?

1 answer

-2

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

What is a. htaccess file?

The files. htaccess files are Apache access and configuration files, they are files read by Apache every time you try to access a file that is inside a folder (or sub folders) where there is a file .htaccess. In this file we can create access lock rules, URL redirects and 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 get deeper into the subject follow this step by step, it is very simple to implement! http://blog.thiagobelem.net/aprendendo-urls-amigaveis

Browser other questions tagged

You are not signed in. Login or sign up in order to post.