简体   繁体   中英

htaccess - Friendly url with redirection

I have been looking for several solutions on the web but as I have always had problems interpreting the htaccess, I have not achieved what I wanted.

I have a website with the following type of link:

https://sub.example.com/search.php?gosearch=new+music+techno
https://sub.example.com/search.php?gosearch=nice-music-rock

And I would like to obtain a link in this way:

https://sub.example.com/search/new-music-techno

I also have a problem, when in my form I press enter, this automatically adds the "+" symbol to all the spaces and I do not know with what method the change would be made automatically to a "-", if with PHP, with JQuery or with .htacess.

In parallel I also have this type of links:

https://sub.example.com/topmusic.php

And I would like to obtain this type of link:

https://sub.example.com/topmusic/

Is it possible to implement everything with htacess?

Do I need to make several conditions or just one?

Is it possible that old urls are redirected automatically to the new form once the user clicks on them?

You can use like this

RewriteRule ^search/(.*)$ search.php?gosearch=$1 [NC,L,QSA]

And on search.php you need to replace the code. htaccess will send the whole string next to "search/" on search.php file under gosearch $_GET parameter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM