我工作在PHP有点定制MVC项目时遇到的htaccess的一些问题。本来,我的htaccess的是路由的所有流量在我的根目录的index.php,并通过其余的路径作为参数。这是工作完美地与此code:
I'm working on a little custom MVC project in PHP and am having some issues with the htaccess. Originally, my htaccess was routing all traffic to index.php in my root dir, and passing the remaining path as an argument. This was working perfectly with this code:
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ index.php?path=$1 [NC,L,QSA]
我有现在的问题是,我需要index.php文件移动到/ public目录。为此,我在网上寻找答案,并发现了一个code片断的有点的工作,因为它似乎到那里只要是刚打/,但只要链接变为/寄存器/或其他任何东西,它只是404的。
The problem I'm having now is that I need to move the index.php file into a /public directory. I scoured the internet for answers, and found a code snippet that kinda works in that it seems to get there as long as it is just hitting /, but as soon as the url becomes /register/ or anything else it just 404's.
# Get rid of /public/ in the URL, and route all requests through # the Index.php file RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ /public/index.php?path=$1 [NC,L,QSA] RewriteCond %{REQUEST_URI} !/public/ [NC] RewriteRule ^(.*?)/?$ public/$1 [L]
我知道,最后一行使得当有重写到index.php呢?这似乎正确的,我(至少它传递参数就像我想要的!)路径没有任何意义,但没有这两行它不似乎工作,我一直在尝试和示数这几个小时。希望有人可以帮帮忙!干杯!
I know that last line makes no sense in when there is the rewrite to index.php with ?path that seems proper to me (at least it passes the argument like I want!) but without both these lines it doesn't seem to work, and I've been trial-and-erroring this for hours. Hopefully someone can help out! Cheers!
推荐答案请在你的.htaccess仅此内容:
Keep only this content in your .htaccess:
DirectoryIndex index.php RewriteEngine On RewriteRule ^/?$ public/ [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ public/?path=$1 [L,QSA]更多推荐
.htaccess的公用文件夹重写规则
发布评论