HTTPS on laravel5 not fully working - apache

I have been trying to make HTTPS work on Laravel.
The routes do no longer work when the Laravel application goes on HTTPS.
Expected: the route loads the view.
Result: 404 Not found page.
Note: that this does work without https.
Here is my apache2 conf
<VirtualHost *:80>
ServerAdmin email#something
ServerName dev.something
DocumentRoot /var/www/something/development/public_html
DirectoryIndex index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Options -Indexes
<Directory "/var/www/something/development/public_html/">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
AuthUserFile /var/www/something/.htpasswd
AuthName "Password please"
AuthType Basic
Require valid-user
</Directory>
Here is my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The following code forces laravel5 to go into secure mode.
app/Providers/AppServiceProvider.php
public function boot()
{
\URL::forceSchema('https');
}
Packages like Barryvdh\Debugbar could no longer load their assets.
I honestly no longer have a clue how I could do this.
If you know something about this please respond!

Related

Error when deploying cakephp application on ubuntu

Good morning,
I’m currently using Cakephp 3 version to develop an application. It should be online on an Ubuntu server and through the subdomain: http://etraining.minmap.cm
To do this, I configured a virtualHost, with the content :
<VirtualHost *:80>
ServerName etraining.minmap.cm
ServerAlias www.etraining.minmap.cm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/etraining.minmap.cm/public_html/webroot
<Directory /var/www/etraining.minmap.cm/public_html/webroot>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The content of the .htaccess located at the application folder is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
The content of the .htaccess located at webroot directory is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have followed all the configuration steps outlined in the official documentation.
mod_rewrite is enabled, mbstring and intl extensions are also enabled
But, I have 500 Internal Server Error:
This is the error reported in my Apache error.log:
I don’t know if I misconfigured Apache, my .htaccess files, and/or the config/app.php?
You should enable apache re-write module. It will work
"sudo a2enmod rewrite"
"sudo service apache2 restart"
Update .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Vue.js Apache configuration with 301 https redirection (mode history)

I'm using vuejs with mode history enabled, and on the docs I find this Histoy mode docs
but then using Let's Encrypt with certbot I run a command to generate an ssl certificate, but now because of the redirection the following configuration no longer works.
<VirtualHost *:80>
ServerName virtuafest.vir.mx
ServerAdmin webmaster#localhost
DocumentRoot /var/www/virtuafest17/dist
<Directory /var/www/virtuafest17/dist>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =virtuafest.vir.mx
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
How can I solve this without having to create an .htaccess file for the Rewrite conf?
Locate VirtualHost: *:443 in etc/apache2/apache2-le-ssl.conf and add your mod_rewrite there.

os x MAMP apache virtual host laravel project misconfigured

MAMP is installed in a MacBook. I use the MAMP apache.
Based on many online resources, I have done the following:
I added 127.0.0.1 my-site.local to file /etc/host.
I uncommented Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf in /Applications/MAMP/conf/apache/httpd.conf.
In /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf, I added
<VirtualHost *:80>
DocumentRoot "/Users/myname/laravel/mysite/public"
ServerName my-site.local
ServerAlias my-site.local
<Directory "/Users/myname/laravel/mysite/public">
DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
In /Users/myname/laravel/mysite/.htaccess file:
<IfModule mod_rewrite.c>
Options +Indexes +FollowSymLinks +MultiViews
RewriteEngine On
#RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Require all granted
</IfModule>
After all, localhost, localhost/MAMP, localhost/phpMyAdmin, all work, EXCEPT for my-site.local.
It shows 500 Internal server error. The server encountered an internal error or misconfiguration and was unable to complete your request.
Problem Solved!
Because the apache has been updated to apache2.2,
in the Applications/MAMP/conf/apache/extra/httpd-vhosts.conf,
change Require all granted to Satisfy Any.
That is it!
It took me two days to figure it out~

Laravel: Apache alias for URLs with trailing slash

I have a Laravel website in directory /home/user/Documents/laravel-training.
I would like to visit my website from http://localhost/dev/,
so I set an alias in /etc/apache2/sites-enabled/000-default.conf.
Here is my 000-default.conf:
<VirtualHost *:80>
ServerName foo.example.net
ServerAdmin foo#example.org
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /dev /home/user/Documents/laravel-training/public
<Directory /home/user/Documents/laravel-training/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I also added RewriteBase /dev to the beginning of /home/user/Documents/laravel-training/public/.htaccess.
Now, I can visit my website successfully in case the URL does not ends with a slash.
For example, if I add the following route:
Route::get('test', function() {
return view('welcome');
});
Then I can visit it from http://localhost/dev/test.
But if my URL is http://localhost/dev/test/, the server will incorrectly redirect my page to http://localhost/test, and causes a 404 Not Found error.
Not Found
The requested URL /test was not found on this server.
Apache/2.4.12 (Ubuntu) Server at localhost Port 80
Does anyone know how to fix this problem?
In response to Stefano Ortisi's comment:
I did not change anything else in .htaccess. I just kept the default settings.
RewriteBase /dev
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
It is not an error that it redirects without the trailing slash.
In your public/.htaccess as you can see there is the following lines:
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
^^^ as the comment states that will redirect a url with a trailing slash if it is not a folder. If you remove that you will see it will not redirect you.

Setting up Symfony2 to work with apache + php-fpm

How does one set up Symfony2 to work on Apache (Apache 2.4) combined with php-fpm?
The aim is to get rid of the .htaccess files and move everything into the apache config.
Without worrying about PHP-FPM, the config looks something like this:
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>
This thread is for me to post my own findings (and perhaps be corrected if I got it wrong!).
I prefer to just use ProxyPassMatch to make this work. By using this method, your rewrite rules in .htaccess don't need to be changed.
Here is my Apache2 vhost file:
<VirtualHost 192.168.100.51:80>
ServerName grae.labs.brainglove.com
ServerAlias www.grae.labs.brainglove.com
DocumentRoot /srv/symfony2/2.4.4/grae/web
DirectoryIndex app_dev.php
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/srv/symfony2/2.4.4/grae/web/$1
<Directory /srv/symfony2/2.4.4/grae/web>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>
ErrorLog /var/log/httpd/grae.labs.brainglove.com_error.log
CustomLog /var/log/httpd/grae.labs.brainglove.com_access.log combined
The only line you need to add is the ProxyPassMatch. Everything else stays the same.
Don't forget to change the IP address and path to your symfony2 web directory.
To pass a request through to PHPFPM, the suggested RewriteRule was:
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2fto%2fwww.sock/%{REQUEST_FILENAME} [P,END]
Here's what I ended up. It seems to be working so far, but perhaps there's a better way?
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
# Need to add the phpfpm call here so that php files (including app_dev.php) are passed to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
# The main phpfpm call is added at the end to pass php requests through to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>