404 error for mod_rewrite using SSL and MAMP - zend-framework

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...)
In Mamp I have 2 virtualhosts set up both pointing to the same web directory (webroot/public/):
secure.myapp.com
myapp.com
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!

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.

Related

Apache2 - Reverse Proxy: Restrict Proxy Pass to just one special URL

At the moment I have the following code in my Config of Apache2.
So on every request on
http://[ExternalAdress]/vis/vis
is redirected to
http://[InternalAdress]/vis
<IfModule mod_proxy.c>
ProxyRequests off
RewriteEngine On
redirectmatch ^/vis/$ /vis/
rewritecond %{REQUEST_URI} ^/vis/
rewriterule (.*) $1 [PT]
rewritecond %{HTTP_REFERER} http://[ExternalAdress]/vis/
rewriterule ^/(.*) /vis/$1 [PT]
ProxyPass /vis/ http://[InternalAdress]:8082/ nocanon timeout=10
ProxyPassReverse /vis/ http://[InternalAdress]:8082/ timeout=10
</IfModule>
<IfModule mod_proxy.c>
RewriteEngine On
Redirectmatch ^/socket.io$ /socket.io/
RewriteCond %{REQUEST_URI} ^/socket.io/
RewriteCond %{QUERY_STRING} transport=websocket
RewriteRule ^/(.*) /wss/$1 [PT]
ProxyPass /wss/ ws://[InternalAdress]:8082/ timeout=1200 Keepalive=On
#ProxyPassReverse / ws://[InternalAdress]:8082/
</IfModule>
But now I want to change my code so that only one specific URL will be redirected and others not.
For example:
http://[ExternalAdress]/vis/vis/index.html?abc#123 shall be redirected to
http://[InternalAdress]/vis/index.html?abc#123
but
http://[EnternalAdress]/vis/vis/index.html?def#456 shall not be redirected to anywhere
How has my code to be changed to be sure that only one specific URL will be redirected and others not?

Redirect from HTTPS to HTTPS of other website

I have read some other questions which are doing almost the same stuff but I wasn't able to replicate the same.
https://serverfault.com/questions/167395/redirect-https-to-another-https
Apache HTTPS to HTTPS Redirection
(I have tried both)
When users click or enter the https:// version I want to redirect my website (which is https://website1.com) to another website (https://website2.com).
What I have achieved till now is when the user clicks on http://website1.com version of the site, they are getting redirected to https://website2.com but when https://website1.com it loads the https://website1.com, no redirection happens.
I'm using Apache HTTPD and below is my httpd.conf file entry:
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>
Seems OR condition is missing for HTTP.
The following code should work, although I haven't tested it.
<VirtualHost *:80>
ServerName website1.com
ServerAlias www.website1.com
RewriteEngine On
RewriteCond %{ENV:HTTPS} [OR]
RewriteCond %{ENV:HTTP} on
RewriteRule ^/?(.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^(.*)$ https://website2.com/$1 [R=301,L]
RedirectPermanent / https://website2.com/
</VirtualHost>

Deploying Laravel to Bluehost

I was wondering if anyone has had any experience deploying larval to blue host? I was flowing an youtube tutorial that showed how to deploy a larval application to a shared hosting service. It was using Godaddy.com, however, i was using Bluehost, and it didn't work as expected. However I managed to getting to not return an internal server error.
What I did was to configure the .env file so that it had my correct database information and my APP_URL to point to my domain.
The youtube tutorial said I should also remove everything from the public folder and place it in the applications main folder, which on Bluehost is the public_html folder. I also changed the .htaccess and removed the public in the rewrite that handles the redirects for trailing slashed.
Now, when I point to my website, all that is served up is a blank screen. but something seems to be working because I uploaded an html webpage that renders to the browser. I just wondering where do I go from here to get the entire site running.
i'm using php 5.6.
Any help would be great. Thank you
I think you are using shared hosting
Follow these steps
1: After upload files to public_html move all your /public files in public_html folder All files like index.php, .htaccess and assets folder etc
2: Find the following line in index.php
require __DIR__.’/../bootstrap/autoload.php’;
require __DIR__.’/../project/bootstrap/autoload.php’;
change to
require __DIR__.’/bootstrap/autoload.php’;
require __DIR__.’/project/bootstrap/autoload.php’;
That’s it. Well then, have fun.
check that the PHP version is correct for Laravel
in cPanle enable FastCGI for PHP
open file .htaccess located in /public and edit
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteBase /public/
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
This is my .htaccess codes which are different in different server.
#Default Setup
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
//bluehost------------
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
RewriteBase /
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

Apache virtual host on a specific directory

I need my site to have a virtual host on a specific directory for my zend application. When user enters www.example.com it should go to normal document root but when user navigates to www.example.com/cms it should go to /var/www/cms/public which its .htaccess file is like this:
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]
On localhost I added this lines to /etc/apache/httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "/var/www/cms/public"
ServerName persian_literature
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<Directory "/var/www/cms/public">
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now http://localhost/ goes to /var/www/cms/public and every thing works. My question is how should I change change above code, to force http://localhost/ to be the normal directory root (so I could use other applications) and http://localhost/cms to be the virtual host?
A virtual host is done at the hostname/domainname level, not at a directory level. You can use an alias to point the URI /cms to some other directory on your server by putting
Alias /cms /var/www/cms/public
in a .conf file (this will not work in .htaccess)
Maybe a symlink (symbolic link)? You still should have the entry of course. And you'll have to put in the config (vhost config I think, maybe .htaccess) that apache should follow the symlink.

Zend MVC - htaccess redirect

All,
My Zend framework Application structure is like this:
billingsystem
-application
-design
--css
--struct.css
--icons
--styles
--images
--js
--common
--thirdparty
-public
--index.php
--.htaccess
-library
-- Zend
My Apache VHost is like this:
<VirtualHost *:80>
ServerAdmin webmaster#billingsystem.localhost
DocumentRoot /opt/lampp/htdocs/xampp/billingsystem
ServerName billingsystem
ErrorLog logs/billingsystem.localhost-error.log
CustomLog logs/billingsystem.localhost-access.log common
<directory /opt/lampp/htdocs/xampp/billingsystem>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
My .htaccess in public folder is like this:
RewriteEngine on
# The leading %{DOCUMENT_ROOT} is necessary when used in VirtualHost context
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]
If I browse to http://billingsystem, it shows the apache directory path on the browser. If I go to http://billingsystem/public, the application executes code on the web page. Is it possible to create or modify .htaccess file such that, when a user browses to http://billingsystem, it should redirect the browser to http://billingsystem/public and execute the code instead of showing the directory structure?
Also, how can I redirect the user to "public" directory when he tries to access any folder through the browser?
I just went through something like this on a site. My solution was that I needed to use two .htaccess files on the domain. One in the root level of the site and another in the public folder.
So, the one at the root of the domain looks like this:
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options +FollowSymLinks
RewriteEngine On
#Zend Rewrite Rules
RewriteRule ^(.*)$ /public/$1 [NC,L]
AddHandler php5-script .php
Within the public folder I have the following rules in place:
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*)$ index.php [NC,L]
This seems to work well to get all content trafficking through the Zend framework.
Hope this is helpful.
- liam
To directly answer your question you can place a .htaccess directly in the billingsystem folder with a rewrite rule:
RewriteRule ^(.*)$ /public/$1 [NC,L]
However, your setup should look more like the following:
File System
billingsystem
-application
-design
-public
--index.php
--.htaccess
-library
-- Zend
Virtual Host
<VirtualHost *:80>
ServerAdmin webmaster#billingsystem.localhost
DocumentRoot /opt/lampp/htdocs/xampp/billingsystem/public
ServerName billingsystem
ErrorLog logs/billingsystem.localhost-error.log
CustomLog logs/billingsystem.localhost-access.log common
<directory /opt/lampp/htdocs/xampp/billingsystem/public>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
.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]
Now the question that remains is that i know you have stuff in you design directory that aparently needs to be web accessible... Can you elaborate on the directory structure in design so that we can figure out what you need to do (if anything) to properly access the various types of files contained in it?