29176

404 error for mod_rewrite using SSL and MAMP

I am building an app in Zend Framework at the moment and testing it all locally. I have Mamp Pro as my web server and I have a self-signed SSL which all seems to work. My problem comes when I try to do mod_rewrite - I just get 404 pages.

The way I have things set up (which may not be the best way...)

<hr>

In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):

    <li>secure.myapp.com</li> <li>myapp.com</li> </ul>

    In my public directory is my index.php file and my .htaccess file. The contents of the .htaccess file are:

    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]

    When I visit http://myapp.com everything routes as it should using the mod_rewrite. But when I go to https://secure.myapp.com the index page is fine, but URL routing stops working and it appears to be that the .htaccess file is being ignored.

    In my ssl.conf I have the following:

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

    Does anybody have any ideas on this? I'll be sooooo appreciative of the help as it's seriously hindering my development!

    Answer1:

    Well I'm pretty sure that I have got this working. Basically, a big problem I had is that Mamp does not store vhosts.conf as an accessible file. Instead this is an aliased application file.

    I think what happens is that the virtualhosts are all dynamically created all on the standard http port, in my case 80. However I needed to be able to access the port 433 vhost config to enable FileInfo. So my workaround is to ditch my .htaccess file and stick the following ALL into my ssl.conf file.

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

    I had to add DOCUMENT_ROOT in front of my file and directory checks, and a forward slash in front of index.php. If I could have put this into a "Directory" then I think I could have avoided these changes, but Apache won't restart when I add this parameter.

    The only thing I didn't try was adding the info to MAMP's httpd.conf, but I have a feeling the same restrictions may be in place.

Recommend

  • Elasticsearch with apache2 ssl proxy
  • Starting, stopping or restarting apachectl always returns “ without matching ”
  • Aggregations in Java client through JSON query - without AggregationBuilder
  • CodeIgniter on 1and1 Error Reporting
  • Doctrine2: Type x already exists
  • Create dynamic subdirectories using htaccess and php
  • Too many Redirects after switching WordPress to https
  • htaccess will not rewrite subdomains
  • Mod_rewrite: Force SSL on specific pages. Add www on none-secure pages
  • Node can't scrape certain pages
  • Simple command-line app I/O in Dart
  • Can't configure nginx as a proxy for tomcat with context path
  • What is wrong in my MVC implementation?
  • https in htaccess and order of rules (using Expression Engine)
  • Removing the .php file extension from the URL Request
  • Version in docker-compose is unsupported
  • how to bypass pinentry (passphrase screen) while decrypting a file using gpgme
  • three.js WebVR example code works on threejs.org but not on my local server
  • sudo easy_install for SimpleITK not that easy
  • Unix Network Programming Clarification
  • How to log in to an HTTPS website with Jsoup?
  • How to autopopulate a field in SugarCRM form
  • python script hangs on input method when running spark
  • Differences in dis-assembled C code of GCC and Borland?
  • Get one-time binding to work for ng-if
  • Is there any way to access browser form field suggestions from JavaScript?
  • C# - Serializing and deserializing static member
  • Sending data from AppleScript to FileMaker records
  • How to include full .NET prerequisite for Wix Burn installer
  • Bitwise OR returns boolean when one of operands is nil
  • Is it possible to post an object from jquery to bottle.py?
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal