【问题标题】:How to remove index.php from url in Zend Framework如何在 Zend Framework 中从 url 中删除 index.php
【发布时间】:2013-12-21 07:17:57
【问题描述】:

我正在使用 Zend Framework 1.12 开发这个应用程序。我想使用.htaccess 摆脱index.php。现在我的网址是这样的:

http://foo.com:10080/Reports_Century/public/index.php/reports/neworders

我希望能够看起来像这样

http://foo.com:10080/Reports_Century/public/reports/neworders

有可能吗? 我的 htaccess 看起来有以下几行:

RewriteEngine On
RewriteCond% {REQUEST_FILENAME}-s [OR]
RewriteCond% {REQUEST_FILENAME}-l [OR]
RewriteCond% {REQUEST_FILENAME}-d
RewriteRule ^ .* $ - [NC, L]
RewriteRule ^ .* $ index.php [NC, L]

谢谢。

【问题讨论】:

  • 上述.htaccess文件的位置是什么?
  • 它在公共文件夹中的 id
  • 感谢您的回复,在下方发布了答案。

标签: .htaccess zend-framework


【解决方案1】:

让你的public/.htacess 像这样:

RewriteEngine On
RewriteBase /Reports_Century/public/

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteRule ^(.+)$ index.php/$1 [L]

【讨论】:

  • 没用。我仍然收到 404。我不应该收到 500 错误代码而不是 404。我如何确定 mod_rewrite 已启用。
  • 您使用哪个 URL 来测试此规则?
  • 不应该是:http://foo.com:10080/Reports_Century/public/reports/neworders 你的网址中缺少/public/
  • 即使对公众也不起作用。如何确定我的重写是否启用?
  • mod_rewrite 已启用,否则您将收到 500 错误。您的 .htaccess 中是否还有其他规则,或者系统中是否还有其他 .htaccess?
【解决方案2】:

尝试在RewriteEngine On下方添加此内容

RewriteRule ^index\.php/(.+)$ /public/$1 [L,R]

【讨论】:

  • 它不起作用,乔恩。有什么想法吗?我得到一个 404
【解决方案3】:

没有 index.php 的版本在 Zend 中是默认的。您不必更改默认的 .htaccess。 我敢打赌你没有在 apache* 中启用重写模块或在配置中禁用重写。

* 将rewrite.load 文件复制到apache 中的mods-enabled 文件夹(在ubuntu 上它位于/etc/apache

【讨论】:

    【解决方案4】:

    终于找到问题所在了。问题是 index.php/ 之后的 $1。

    最终的.htaccess是:

    RewriteEngine On
    RewriteBase /Reports_Century/public/
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    
    RewriteRule ^(.+)$ index.php [L]
    

    @Anubhava 给你一个加分以加快时间并帮助我解决问题。

    【讨论】:

      【解决方案5】:

      您还需要在apache2/sites-enabled/default 中为您的目录激活“AllowOverride All”:

          <Directory /var/www/html/public>
                  AllowOverride All
          </Directory>
      

      【讨论】:

        猜你喜欢
        • 2012-12-30
        • 1970-01-01
        • 2014-10-10
        • 2012-05-15
        • 1970-01-01
        • 2015-07-26
        相关资源
        最近更新 更多