我有一个基本的MVC结构和一个restful uri设计:
mysite.com/appdir/:index/:controller/:action/我想隐藏索引路由参数,这样我的uri看起来就像:
mysite.com/appdir/:controller/:action/我的基本文件夹结构是:
appdir/
app/
-->Controller/
-->Model/
-->View/
config/
library/
public/
-->.htaccess
-->index.php
.htaccess
index.phpappdir/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>appdir/public/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>我似乎不能隐藏索引,我已经尝试了许多重写规则,但似乎都不起作用。使用CodeIgniter,我通常可以添加RewriteRule ^(.*)$ index.php?/$1 [L,QSA]并解决问题,但我已经为此工作了3个小时,但没有成功。
发布于 2013-05-19 05:39:30
首先,请求路径总是以/开头,所以第一条规则应该这样写
RewriteEngine on RewriteRule ^/(.\*)$ public/$1 [L] 那么我想在public dir的htaccess中你应该使用
RewriteBase /public
最后--为什么不直接把public设置为why服务器的DocumentRoot,并将所有规则放到单个文件中呢?在您的设置中,appdir/index.php永远无法访问。
https://stackoverflow.com/questions/16628987
复制相似问题