Laravel project not showing me index.php - .htaccess

I'm using Win10 with WAMP server.
I installed wamp and created my virtual host
<VirtualHost *:80>
DocumentRoot "c:/wamp/www"
ServerName localhost
ServerAlias localhost
<Directory "c:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/project/public"
ServerName project
<Directory "c:/wamp/www/project/public">
Options Indexes FollowSymLinks
AllowOverride All
Require local
</Directory>
</VirtualHost>
Then i used Composer + git to get back a project (laravel), but when I try to access to my project it shows me the folders Inside public and not the index.php
Here is my .htaccess
<IfModule mod_rewrite.cs>
<IfModule mod_negotiation.c>
Option -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>

If its not executing PHP, check your WAMP installation. Also,check php-mcrypt extension is installed and active.In the Virtual host i use the below configuration:
<VirtualHost *:80>
ServerName homestead.app
DocumentRoot "c:/wamp/www/project/public"
<Directory "c:/wamp/www/project/public">
Require all granted
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
Where homestead.app is your name and add it to the host file

Related

Apache Website + Nodejs backend + Websocket server

I'm trying to make my website works with a nodejs backend and a websocket server
my website is entirely in https
my node backend is on port 8080 with my websocket server on 8080
I made a virtualhost like that
<VirtualHost *:8080>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/socket.io [NC]
RewriteCond %{QUERY_STRING} transport=websocket [NC]
RewriteRule /(.*) ws://localhost:8080/$1 [P,L]
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com
ServerName www.example.com
ServerAlias example.com
<Directory /var/www/example.com>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
<Directory /var/www/example.com/wp-content>
Options -Indexes +FollowSymLinks +MultiViews
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15553000; includeSubDomains; preload"
</IfModule>
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
</VirtualHost>
But when I tried to go on myip:8080 it doesn't work and same for connecting to my websocket
What did I do wrong ?
Enable mod_proxy_wstunnel
Then you should be able to forward only your location to your websocket server.
ProxyPass /wssurl/ ws://127.0.0.1:8080/
Ok after a lot of work. I figured out. I think the problem come with the firewall when I installed my website.
so I have to proxypass everything on my secure connection.
The mod_proxy_wstunnel is not working because when I tried to connect with wss:// so I had to use rewriteEngine.
Here is my final working virtual host
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot /var/www/example.com
ServerName www.example.com
ServerAlias example.com
<Directory /var/www/example.com>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
Require all granted
</Directory>
<Directory /var/www/example.com/wp-content>
Options -Indexes +FollowSymLinks +MultiViews
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15553000; includeSubDomains; preload"
</IfModule>
ErrorLog /var/log/apache2/error.example.com.log
CustomLog /var/log/apache2/access.example.com.log combined
ProxyRequests On
ProxyPreserveHost On
ProxyPass /api/test http://localhost:8080
ProxyPassReverse /api/test http://localhost:8080
RewriteEngine On
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:8080/$1" [P,L]
</VirtualHost>

How to redirect to https in Apache2

We are hosting magento site in AWS. I configured SSL using certbot and it automatically created conf file. But when I am trying to hit the URL. It is showing too many attempts. Below are the Apache2 configuration files.
mysite.conf
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento>
Allowoverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.example.com [OR]
RewriteCond %{SERVER_NAME} =example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
mysite-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento>
Allowoverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
In Magento, I changed config_url to https://example.com
Error
This page isn’t working
mysite.com redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
Did you restart apache? It seems like you're hitting VHOST on port 80 and redirecting constantly.

I cant get htaccess to work in vhost

I have deployed a server apache in ubuntu 16.04 which is devided in some virtual hosts.
I want to get rid of index.php in the url but I cant get my htaccess to work I will be deeply great-full for any help I can receive. I prefer to solve the problem in htaccess and not in apache itself because there are also other configurations I need to include in htaccess
Conf file
<VirtualHost *:80>
<Directory var/www/cartwebs.com/public_html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin iosef#cartwebs.com
ServerName cartwebs.com
ServerAlias www.cartwebs.com
DocumentRoot /var/www/cartwebs.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.cartwebs.com/$1 [L,R=301]
</IfModule>

How to redirect all traffic to https except subdomains

I have recently redirect all traffic to https but I want to keep my subdomains on http only. Please help me to sort out this.
this is my rewriterules
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
this is my virtual host code
<VirtualHost *:80>
ServerAdmin test#example.com
ServerName staging.example.com
ServerAlias staging.example.com
SetEnv ENVIRONMENT staging
DocumentRoot /var/www/staging/
ErrorLog /var/log/apache2/example_staging_error.log
CustomLog /var/log/apache2/example_staging_access.log combined
<Directory /var/www/staging>
AllowOverride All
Include /etc/apache2/sites-available/example_dir_rules.conf
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin test#example.com
ServerName example.com
ServerAlias example.com
SetEnv ENVIRONMENT production
DocumentRoot /var/www/production/
ErrorLog /var/log/apache2/example_production_error.log
CustomLog /var/log/apache2/example_production_access.log combined
<Directory /var/www/production>
Include /etc/apache2/sites-available/example_dir_rules.conf
</Directory>
</VirtualHost>
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
#Listen 443
<VirtualHost *:443>
SSLEngine on
SSLHonorCipherOrder On
-------------ssl code----------
ServerName example.com
-------------ssl code----------
ServerAdmin test#example.com
ServerName example.com
ServerAlias example.com
SetEnv ENVIRONMENT production
DocumentRoot /var/www/production/
ErrorLog /var/log/apache2/example_ssl_error.log
CustomLog /var/log/apache2/example_ssl_access.log combined
<Directory /var/www/production>
Include /etc/apache2/sites-available/example_dir_rules.conf
</Directory>
</VirtualHost>
Please help me to sort out this. Thanks in advance.
You have two choices.
1. Either you add a condition in your file to only match main domain
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Note that the rule to match www main domain can be removed since your main domain is example.com (no trace of www in your vhosts).
Warning: useless in some cases, you should not include the same file in all vhosts (see next point).
2. Or you can directly put a rule in example.com (http) vhost block. Indeed, others two (example.com for https and stagging subdomain) do not require rules to do what you want.
So, your config should look like this
<VirtualHost *:80>
ServerAdmin test#example.com
ServerName staging.example.com
ServerAlias staging.example.com
SetEnv ENVIRONMENT staging
DocumentRoot /var/www/staging/
ErrorLog /var/log/apache2/example_staging_error.log
CustomLog /var/log/apache2/example_staging_access.log combined
<Directory /var/www/staging>
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin test#example.com
ServerName example.com
ServerAlias example.com
SetEnv ENVIRONMENT production
DocumentRoot /var/www/production/
ErrorLog /var/log/apache2/example_production_error.log
CustomLog /var/log/apache2/example_production_access.log combined
<Directory /var/www/production>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</Directory>
</VirtualHost>
LoadModule ssl_module /usr/lib/apache2/modules/mod_ssl.so
#Listen 443
<VirtualHost *:443>
SSLEngine on
SSLHonorCipherOrder On
-------------ssl code----------
ServerName example.com
-------------ssl code----------
ServerAdmin test#example.com
ServerName example.com
ServerAlias example.com
SetEnv ENVIRONMENT production
DocumentRoot /var/www/production/
ErrorLog /var/log/apache2/example_ssl_error.log
CustomLog /var/log/apache2/example_ssl_access.log combined
<Directory /var/www/production>
</Directory>
</VirtualHost>

Cannot found the route without the app_dev.php

When I go to my website like this :
example.com/ or
example.com/app_dev.php
That works fine.
But when I try to go to a different route like
example.com/api/route/option
I got an error 404, however when I go to
example.com/app_dev.php/api/route/option
That is working fine.
This is my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^app_dev.php - [L]
RewriteRule ^app.php - [L]
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ app.php [QSA,L]
RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
And this is my virtualhost
<VirtualHost *:80>
ServerName example.com
ServerAdmin my_mail
DocumentRoot /var/www/html/example/web/
DirectoryIndex app_dev.php
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Got an idea ?
Thanks !
Your virtual host file doesnt enable overrides meaning your .htaccess file isnting being read. Try adding this to your virtual host file:
<Directory /var/www/html/example/web/>
AllowOverride None
Order Allow,Deny
Allow from All
</Directory>
You may also want to look into other setup options as documented here: http://symfony.com/doc/current/setup/web_server_configuration.html

Resources