I know that this question may be duplicate or answered in the past but I have read the apache.org site and have seen many other similar answers and I cannot find a proper solution to my problem so far since I am novice in the .htaccess and apache.
For simplicity reasons let's assume that the URL of my site is: https://www.example.com
The main page is index.php and there is a submit form with 3 select/dropdowns elements with names: sp, ar and in. sp is mandatory (user has to enter a value), ar and in are optionals.
When I submit the form, the file results.php is executed. When all 3 dropdowns have values, the form of the submitted URL is:
1) https://www.example.com/results.php?sp=textvalue1&ar=textvalue2&in=textvalue3
Moreover, depending if the ar and in have (or haven't) values, the other possible forms of the URL are:
2) https://www.example.com/results.php?sp=textvalue1&ar=&in=
3) https://www.example.com/results.php?sp=textvalue1&ar=textvalue2&in=
4) https://www.example.com/results.php?sp=textvalue1&ar=&in=textvalue3
I want to convert these "ugly" URLs to SEO-friendly URLs.
For case 1 (all 3 dropdowns have values), I would like to submit the form and see in my browser's URL field:
(case 1) https://www.example.com/textvalue1/textvalue2/textvalue3
and get the same results (important)!
Similarly, I want the other SEO-friendly URLs to be:
(case 2) https://www.example.com/textvalue1
(case 3) https://www.example.com/textvalue1/textvalue2
(case 4) https://www.example.com/textvalue1/textvalue3
My guess is that I have to do 2 things: First, to convert the ugly URL to a SEO-friendly URL and, second, to treat the new SEO-friendly URL as if it was the old ugly one.
I have tried the following commands in my .htaccess file for case 2 so far but nothing happened:
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/results\.php\?sp=([a-zA-Z]+)\s [NC]
RewriteRule ^ /%1? [R=302,L]
RewriteRule ^/([[a-zA-Z]]+)$ /results.php?sp=$1 [L]
https://www.example.com/foo/baractually tries to express: what isbarmeant to be a value for?arorin? - arkaschabarto that you captured in the incoming request? Will you assign it toaror toin? This is not defined in any way in your question and I cannot sport any logic for that. So again: can you name a condition or a logic by which to decide what case is actually meant by the URL? - arkascha