我为我的城市编写了一个本地名称/电话/地址搜索引擎。
用户必须能够通过访问以下任一 URL 来快速访问结果:
-
search by number
- http://domain.com/5554651
-
search by lastname
- http://domain.com/smith
- http://domain.com/smith%20johnson
-
search by lastname and first name
- http://domain.com/smith/andrew
- http://domain.com/smith%20johnson/mary%20elizabeth
这是我当前的 .htaccess 配置:
# 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]
除非用户在姓氏和/或名字中包含空格,否则效果非常好。此外,搜索姓名时不能使用数字。
关于如何在 url 中允许空格有什么想法吗?谢谢!
你能试试这个吗?([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]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)