我正在学习本教程:
http://www.phpro.org/tutorials/Model-View-Controller-MVC.html
本教程指出您应该使用htaccess文件。但是,Apache2文档建议您将.htaccess规则输入标准配置文件以获得更好的性能。
我在 / etc / apache2 / sites-available / default 工作。
这是我到目前为止所做的:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Deny,Allow
Deny from all
</Directory>
<Directory /var/www/>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
</Directory>
<Location /index.php>
Order Allow,Deny
Allow from All
</Location>
使用这些规则,index.php是可访问的,但index.php?rt = blog仍然有效,而index / blog或/ blog则不然。我做错了什么?
答案 0 :(得分:0)
但index.php?rt =博客仍有效
您没有任何规则可以使其无效
和index / blog或/ blog不
您没有任何规则可以使网址看起来像这样,但“/ blog”应该重写为/index.php?rt=/blog
。
尝试类似:
<Directory /var/www/>
RewriteEngine On
RewriteCond %{THE_REQUEST} \ /+index\.php?rt=([^&\ ]+)
RewriteRule ^ /%1? [L,R]
RewriteRule ^/index/(.*)$ /$1 [L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/(.*)$ /index.php?rt=$1 [L,QSA]
</Directory>