我是htaccess的新手,从来不用自己做。但时间到了。
我有一个简单的PHP API,所以我需要将所有URL重定向到index.PHP(PHP将处理路由(,所以
localhost/api/user
localhost/api/post
localhost/api/whatever
转到
localhost/index.php
我想这很简单吧?
RewriteRule (.*) /api/index.php
但我还需要一件事,那就是,当url的最后一个序列是数字时,比如:
localhost/api/user/142
localhost/api/post/675
localhost/api/whatever/2136912
它应该转到转到
localhost/index.php?id=GIVEN_NUMBER
有没有办法做到这一点,或者我应该开始研究PHP解决方案?感谢
创建类似的规则
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php?$1 [L]
然后在index.php上解析请求的URL并采取行动。