php禁止某个链接,php – 使用htaccess忽略链接的某些部分
我有一個關于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]
標簽:htaccess,php,regex,apache,mod-rewrite
來源: https://codeday.me/bug/20190825/1719054.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的php禁止某个链接,php – 使用htaccess忽略链接的某些部分的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php中如何写js代码提示_PHP 如何
- 下一篇: phpstudy搭建网站使用php,教你