我有一个关于htaccess的问题和它的重写.
我有这个代码:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^users/(\d+)*$./profile.PHP?id=$1
RewriteRule ^threads/(\d+)*$./thread.PHP?id=$1
RewriteRule ^search/(.*)$./search.PHP?query=$1
其中example.com/users/123等于example.com/profile.PHP?id=123.
如果我改变链接:example.com/users/123/John
将htaccess忽略/ John或ID之后的任何额外字符?
事实上,约翰是123 ID的真实姓名,我希望它是.
解决方法:
不,它不会忽略您URL中的额外部分,因为您在此处使用正则表达式中的$(行尾):
^users/(\d+)*$
将您的规则更改为:
RewriteCond %{SCRIPT_FILENAME} !-d [OR]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^ - [L]
RewriteRule ^users/(\d+) profile.PHP?id=$1 [L]
RewriteRule ^threads/(\d+) thread.PHP?id=$1 [L]
RewriteRule ^search/(.*)$search.PHP?query=$1 [L]