With a select box of towns , i must change the url like that : mywebsite.com/index.php to mywebsite.com/myselecttownvalue/index.php or mywebsite.com/anotherselecttownvalue/index.php
It's possible with an htaccess to manage that ?
Ty for help !
With a select box of towns , i must change the url like that : mywebsite.com/index.php to mywebsite.com/myselecttownvalue/index.php or mywebsite.com/anotherselecttownvalue/index.php
It's possible with an htaccess to manage that ?
Ty for help !
Certainly it is possible to "accept" incoming URLs, that would mean to rewrite them to an internal, existing route which can process the request and respond to it.
Concerning your examples: typically one would leave out the script name, so the URLs would look clean, something like https://example.com/town/myselectedtown
and get internally rewritten to something like /index.php?town=myselectedtown
so that the selected value is available in the $_GET
superglobal variable as $_GET['town']
. Take care to URL-encode the town name though, in case it contains blanks or funny stuff...
Take a look at this example setup:
RewriteEngine on
RewriteRule ^/?town/(.+)$ /index.php?town=$1 [L]
The above rule will work in dynamic configuration files (".htaccess") and in the real http servers host configuration.
You certainly could define your URLs without the /town
token inside, s you suggested (so just https://example.com/myselectedtown
). But that typically raises issues with other URL patterns, since it is never clear if a URL refers to a town name or something else...
And a general hint: you should always prefer to place such rules inside the http servers host configuration instead of using dynamic configuration files (".htaccess"). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only provided as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).