Using spaces in URL and .htaccess

I wrote a local name / phone / address search system for my city.

Users should be able to quickly access results by going to any of these URLs:

This is my current .htaccess config:

# Smart links
RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L]
RewriteRule ^([A-Za-z-]+)$ /html/index.php?lastname=$1 [QSA,L]
RewriteRule ^([A-Za-z-]+)/([A-Za-z-]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]

This works very well, unless the user includes a space in the name and / or name. In addition, no numbers can be used when searching for names.

Any ideas on how to resolve spaces in the url? Thank!

+3
source share
2 answers

? ([a-z-\s]+)

RewriteRule ^([0-9]+)$ /html/index.php?phone=$1 [QSA,L]
RewriteRule ^([A-Za-z-\s]+)$ /html/index.php?lastname=$1 [QSA,L]
RewriteRule ^([A-Za-z-\s]+)/([A-Za-z-\s]+)$ /html/index.php?lastname=$1&name=$2 [QSA,L]
+11
RewriteRule ^([A-Za-z-\s]+)/([A-Za-z-\s]+)$ /index.php?lastname=$1&name=$2 [QSA,L]

\ s .

+1

Source: https://habr.com/ru/post/1789340/


All Articles