zend-framework - 使用 SSL 和 MAMP 的 mod_rewrite 出现 404 错误

标签 zend-framework .htaccess mod-rewrite ssl mamp

我目前正在 Zend Framework 中构建应用程序并在本地进行测试。我有 Mamp Pro 作为我的网络服务器,我有一个自签名的 SSL,似乎一切正常。当我尝试执行 mod_rewrite 时,我的问题来了 - 我只得到 404 页。

我的设置方式(这可能不是最好的方式...)


在 Mamp 中,我设置了 2 个虚拟主机,它们都指向同一个 Web 目录 (webroot/public/):

  • secure.myapp.com
  • myapp.com

在我的公共(public)目录中是我的 index.php 文件和我的 .htaccess 文件。 .htaccess 文件的内容是:

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

当我访问http://myapp.com时使用 mod_rewrite 的所有路由都应该如此。但是当我去 https://secure.myapp.com索引页面没有问题,但 URL 路由停止工作,似乎 .htaccess 文件被忽略了。

在我的 ssl.conf 中,我有以下内容:

<IfModule mod_ssl.c>

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache         dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout  300
SSLMutex  file:/Applications/MAMP/logs/ssl_mutex

<VirtualHost _default_:443>

SSLEngine on
DocumentRoot "/webroot/public"
ServerName secure.myapp.com
ServerAdmin you@example.com
ErrorLog /Applications/MAMP/logs/ssl_error_log
TransferLog /Applications/MAMP/logs/ssl_access_log

SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key

CustomLog /Applications/MAMP/logs/ssl_request_log \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

</VirtualHost>

</IfModule>

有没有人对此有任何想法?我将非常感谢您的帮助,因为它严重阻碍了我的发展!

最佳答案

好吧,我很确定我已经成功了。基本上,我遇到的一个大问题是 Mamp 没有将 vhosts.conf 存储为可访问文件。相反,这是一个带别名的应用程序文件。

我认为虚拟主机都是在标准 http 端口上动态创建的,在我的例子中是 80。但是我需要能够访问端口 433 虚拟主机配置以启用 FileInfo。所以我的解决方法是放弃我的 .htaccess 文件并将以下所有内容粘贴到我的 ssl.conf 文件中。

<IfModule mod_ssl.c>

Listen 443
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl
SSLPassPhraseDialog  builtin
SSLSessionCache         dbm:/Applications/MAMP/logs/ssl_scache
SSLSessionCacheTimeout  300
SSLMutex  file:/Applications/MAMP/logs/ssl_mutex

<VirtualHost mysite.com:443>

    SSLEngine on
    DocumentRoot /webroot/secure
    ServerName mysite.com
    ServerAdmin you@example.com
    ErrorLog /Applications/MAMP/logs/ssl_error_log
    TransferLog /Applications/MAMP/logs/ssl_access_log

    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile /Applications/MAMP/conf/apache/ssl_cert/server.crt
    SSLCertificateKeyFile /Applications/MAMP/conf/apache/ssl_key/server.key

    CustomLog /Applications/MAMP/logs/ssl_request_log \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"

    DirectoryIndex index.php

        <IfModule mod_rewrite.c>
            RewriteEngine on
            RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -s [OR]
            RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -l [OR]
            RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d

            RewriteRule ^.*$ - [NC,L]
            RewriteRule ^.*$ /index.php [NC,L]

            RewriteLog /Applications/MAMP/logs/ssl_rewrite_log
            RewriteLogLevel 3
        </IfModule>

</VirtualHost>

</IfModule>

我必须在文件和目录检查前添加 DOCUMENT_ROOT,并在 index.php 前添加正斜杠。如果我可以将其放入“目录”,那么我想我可以避免这些更改,但是当我添加此参数时 Apache 不会重新启动。

我唯一没有尝试的是将信息添加到 MAMP 的 httpd.conf,但我感觉可能存在相同的限制。

关于zend-framework - 使用 SSL 和 MAMP 的 mod_rewrite 出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1472902/

相关文章:

apache - mod_rewrite 的隐藏功能

html - 目录列表列宽

.htaccess - 使用 Codeigniter 临时关闭站点(301 可能使用 routes.php?)

zend-framework - Zend Framework 以 HTML5 方式附加脚本和样式表

php - LIMIT 1 对于顶级表WITH JOIN

regex - urlrewrite 中 $1 之后的数字

apache - Apache 的 mod_rewrite 使用什么正则表达式风格?

regex - mod_rewrite 可以做数学吗?

php - 使用 Zend 框架创建绝对 URL 的最佳实践?

ZF 表单验证后 PHPunit 测试未通过