我一直在尝试模仿 nodejs/express 如何使用他们的路由。我将所有流量转发index.php
到处理路由(使用AltoRouter)。
我的文件结构是这样的:
-/
--public/
|- assets
|- ...
--routes/
|- route.php
|- ...
--index.php
以这些 url 为例(都应该返回/重定向 404):
http://testsite.com/routes
http://testsite.com/routes/route.php
http://testsite.com/somefile.php
但是,只有资产应该可以像这样直接访问(我不想包括/public/
:
http://testsite.com/assets/image.png
http://testsite.com/assets/styles/style.css
这是我到目前为止所拥有的:
# Make sure mod_rewrite is on
<IfModule mod_rewrite.c>
RewriteEngine on
# This should allow us to get our assets and keep them public
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.(gif|jpg|png|jpeg|css|js|swf)$ /public/$1.$2 [L,NC]
# Forward other traffic to index.php
RewriteRule ^.+$ index.php [L]
</IfModule>
我遇到的一个问题是:http://testsite.com/routes
产生:
我想我的主要问题是任何不公开的东西都不能访问(不确定 .htacces 是否可行)