![](/img/trans.png)
[英]htaccess mod_rewrite & apache2 not rewriting forward slash
[英]Apache2 setting up mod_rewrite and restricting access without .htaccess file
我正在關注本教程:
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無效。 我究竟做錯了什么?
但是index.php?rt = blog仍然有效
您沒有任何規則可以使它行不通
和索引/博客或/博客不
盡管“ / blog”應重寫為/index.php?rt=/blog
,但您沒有任何規則可以使URL看起來像這樣。
嘗試類似:
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.