Modify htaccess to get "friendly" URLs

0

Edit:

At the moment the solutions have not worked for me. The only one that I am testing and that I see that it does access the URL is with the following code:

RewriteEngine On

RewriteRule ^XboxOne/([0-9]+) single.php?id=$1

This leaves me with a URL in localhost as: http://localhost/xboxone/XboxOne/258

The problem that I am finding is that the ID does not take it well, which returns a null array of the database.

I have a small problem with the URLs of my web page. My links are of the style:

http://www.lalalalala.com/single.php?ID=224

http://www.lalalalala.com/noticias/noticias.php?ID=105

The first one is for game technical cards, and the second one and the one that worries me most is the news one. For what they have commented to me it is not the same to have it as I have it to have it for example

http://www.lalalalala.com/noticias/las-mejores-ofertas-de-xbox

The problem is that I have read that you have to be very careful and make a backup, however this is not what worries me, rather the fact that the previous links stop working and can not be redirected. The web is open since November, and I usually publish daily with what I have that concern that the links stop working.

I would like to know if you recommend the change and how to proceed, I understand that something can improve SEO.

    
asked by JetLagFox 14.03.2017 в 15:03
source

2 answers

2

Good afternoon. Firstly point out that you can surely continue using the previous routes, although it is difficult to know without saying that FW you use, if you use a router, etc.

Removing the last to use them you must activate the mod_rewrite module.

Next you should modify your .htaccess following the example:

Options -MultiViews
RewriteEngine On

# 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]

Taken from this thread thread of the official SO.

    
answered by 14.03.2017 в 15:37
0

Hello here, a simple example.

As unfriendly url we have for example:

  

link

And as a friendly url we would understand something like this:

  

link

To achieve this we only create the htacces file and add the following

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.tuweb.com
RewriteRule (.*) http://tuweb.com/$1 [R=301,L]

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ users.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ users.php?user=$1

And modify the links to user profiles by adding the friendly url instead of the unfriendly one.

    
answered by 14.03.2017 в 16:04