Is it advisable to use IDs in friendly URLs?

1

I would like to know if there are any rules that please the eyes of Google. The friendly URLs I use include the ID of what I want to "load" on the page. For example:

http://www.unawebcualquiera.mx/bocadillos/13/bocadillo-con-jamon/

My doubt is that I have seen several websites that do not use these IDs in the URLs. In that case I understand that they search through the text, that is, by bocadillo con jamon . But a question arises that I can not solve.

If in the database the title is bocadillo con jamón , you will not find anything (for the accent). I can not think how these kind of friendly URLs work. I could make the URL be:

http://www.unawebcualquiera.mx/bocadillos/13/bocadillo-con-jamón/

But obviously when doing this, although later I could clean the text and search correctly in the database, I understand that it is a fudge as far as friendly URLs are concerned. Does it affect something to use IDs in the URL in terms of positioning or understanding by the Google robot?

    
asked by JetLagFox 27.01.2018 в 21:40
source

4 answers

4

Accents are not a problem. You receive them encoded for URL ( RFC 3986 ) and you get:

  • With $_GET or $_REQUEST , PHP delivers them decoded (for example, converts to %C3%B3 in ó ). It is not necessary to do anything.

But if you get them directly from the URL:

  • urldecode () when you received it from a chain of search.
    http://url.com/articulo.php?titulo=bocadillo-con-jam%C3%B3n

  • rawurldecode () when it is part of the route .% http://url.com/bocadillo-con-jam%C3%B3n

echo urldecode('bocadillo-con-jam%C3%B3n');
bocadillo-con-jamón


The title as an identifier?

The important issue here is to keep a unique name. For example,

  • Are you sure you're never going to change the name? That that name will serve as unique identifier of your article?

  • Or if it changes, do you want to generate all the code to redirect from bocadillo-con-jamón to bocadillo-con-queso ?

  • And are you willing to validate that no other article will be called bocadillo-con-jamón ?

For those reasons it is more practical with ids.


If you are still interested in using the name of the article as the main identifier, to generate the URL from the text with accents (the inverse), rawurlencode () :

echo rawurlencode('http://web.com/bocadillo-con-jamón');
http://web.com/bocadillo-con-jam%C3%B3n


Google does not take an id against SEO .

  

https://es.stackoverflow.com/questions/134309/es-recomendable-usar-las-id-en-las-urls-amigables

Notice the URL we're in. I assure you that OS does not do badly in the results of Google.


And the .htaccess?

It's just a matter of adding the characters in your rule, including the accents and the ñ, for example:

RewriteRule ^([-0-9a-záéíóúüñ]+)/?$ articulo.php?titulo=$1 [QSA,END]
    
answered by 27.01.2018 / 22:33
source
1

Look when you save URLs in a database, some things will be encrypted such as spaces, Ñ and other special characters then, from the php you will send the URL record with an encode and when you do the you'll use the Decode so you do not have to link

    
answered by 27.01.2018 в 22:13
1

Although your question is more of a forum than of stackoverflow (see the rules of use) I will tell you that it is not recommended or less advisable, it all depends on what you define as search criteria in your database, use the ID is as good as using the slug, in any case nothing should be repeated, an example:

Article of my web ID 13 slug article-of-my-web

http://unawebcualquiera.com/13/articulo-de-mi-web
http://unawebcualquiera.com/articulo-de-mi-web

Any option is good and it is not better or worse and my advice is that you create a method that generates a correct slug, here I leave one

public function getSlug($cadena, $separador = '-')
{

    $slug = iconv('UTF-8', 'ASCII//TRANSLIT', $cadena);
    $slug = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $slug);
    $slug = strtolower(trim($slug, $separador));
    $slug = preg_replace("/[\/_|+ -]+/", $separador, $slug);
    return $slug;
}
    
answered by 27.01.2018 в 23:18
1

When working with an id in the url you should be careful with how you are restricting it, since a user could change the id in the url and see a record of another user that maybe should not see.

Pan-con-jamon or rather the slug's, are usually created in a new field within the database, in the respective table. This slug is just a string, if you want to use the slug as id for a url make sure that this field is unique in the database and that it does not happen again.

When saving the slug in the database you can apply a modification to the string, remove the accents and then save them, they are usually removed since if you want a page visible to everyone in other languages the accent is not It exists.

    
answered by 29.01.2018 в 03:37