【问题标题】:Apache2 setting up mod_rewrite and restricting access without .htaccess fileApache2 设置 mod_rewrite 并限制没有 .htaccess 文件的访问
【发布时间】:2014-02-24 09:00:36
【问题描述】:

我正在学习本教程:

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 无效。我做错了什么?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    但 index.php?rt=blog 仍然有效

    你没有任何规则使它不起作用

    而 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-04
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 2011-05-12
      • 1970-01-01
      • 2012-03-03
      相关资源
      最近更新 更多