我有以下htaccess代码:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/([^/\.]+) index.php?task=location&state=$1&city=$2 [L]
它的URL就像:
website.com/texas/houston
website.com/new-york/new-york
...
如果我访问URL网站/texas/houston/bfdsjfds,我会获得与URL website.com/texas/houston相同的内容。 如何删除" / bfdsjfds"在上面的例子?或者将该页面重定向到404。
答案 0 :(得分:1)
您可以使用结束锚$
仅匹配/state/city
:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)/([^/.]+)/?$ index.php?task=location&state=$1&city=$2 [L]
这会自动为website.com/texas/houston/bfdsjfds
类型的网址返回404。