代码之家  ›  专栏  ›  技术社区  ›  JHollanti

修改noobie问题

  •  1
  • JHollanti  · 技术社区  · 15 年前

    我已经安装了Zend风格的frontcontroller。基本上,它只是将每个url重定向回索引。

    controller/view/ + [additional parameters]

    我想以以下形式创建一些快捷方式:

    RewriteRule ^home /home/index
    RewriteRule ^products /products/view
    
    RewriteRule .* index.php
    

    然而,mod_rewrite似乎忽略了我的重写规则。它不会改变home-to-home/索引,尽管我相当确定它应该能够捕捉到这一点。所以,我认为这与重命名请求uri有关?

    以下是.htaccess文件:

    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule  ^admin/  -  [L]
    RewriteRule  ^media/  -  [L]
    
    RewriteRule  ^home        home/index
    RewriteRule  ^products    products/view
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php
    
    3 回复  |  直到 15 年前
        1
  •  0
  •   Gumbo    15 年前

    当您试图重写刚开始的所有内容时,可能会遇到问题 /home /home/index 因为后者也从 /家 . 您应该使用以下更具体的模式:

    RewriteRule ^home$ home/index
    RewriteRule ^products$ products/view
    

    但其余的都应该很好。

        2
  •  0
  •   Fabian    15 年前

    下面的规则抓住了一切,所以如果它在顶部,它将永远不会考虑任何其他规则。

    RewriteRule .* index.php
    

    Options +FollowSymLinks
    RewriteEngine on
    
    RewriteRule  ^admin/      -  [L]
    RewriteRule  ^media/      -  [L]
    
    RewriteRule  ^home        home/index [L]
    RewriteRule  ^products    products/view [L]
    
    RewriteCond  %{REQUEST_FILENAME} !-f
    RewriteRule  .*           index.php
    
        3
  •  0
  •   JHollanti    15 年前

    到目前为止,我已经猜到了很多。

    如果您使用重写规则来更改 REQUEST_URI 请求URI ,但另一个变量称为 REDIRECT_URI . 这就解释了为什么什么都没有发生。

    RewriteRule ^products products/view [NC,L]
    

    费边提出了这样的建议。他只是在末尾附加index.php,这对我不起作用。如果我不使用index.php,那么一切都可以完美地工作。它神奇地将所有内容重定向到index.php。

    所以现在,一切都在运转,但我不知道为什么一切都在运转。任何能解释这里发生的事情的人都会投赞成票。在那之前,我想我只需要RTFM。