I cant get htaccess to work in vhost - .htaccess

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>

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.

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

Laravel project not showing me index.php

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

force https on subdirectory and redirect non-www traffic to www

So for the past couple hours I've been frustrated with my .htaccess file not working.
I have two subdirectories: secure.mysite.ca and storage.mysite.ca that need to be both ssl encrypted. The sites work when I put https in front of the URL (i.e. https://secure.mysite.ca/ or https://storage.mysite.ca/) but when I put http in front it redirects to my root website (http://mysite.ca/). I want to redirect to the https version of the site when someone tries to go to the unencrypted version.
ALSO I would like to redirect all traffic visiting http://mysite.ca/ to be redirected to http://www.mysite.ca/ (i.e. www in front)
This .htaccess file used to work over a year ago but now it doesn't.
Here is my htaccess file found in the root folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite\.ca$ [NC]
RewriteRule ^(.*)$ http://www.mysite.ca%{REQUEST_URI} [R=permanent,L]
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTP_HOST} ^(secure|storage)\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Am I doing something wrong? Should I be putting an .htaccess file inside the subdirectory?
EDIT: Here is the virtualhost config file for secure.fixnode.ca, storage.fixnode.ca and www.fixnode.ca. Please let me know what I'm doing wrong
storage.fixnode.ca.conf
<VirtualHost *:443>
DocumentRoot "/var/www/fixnode_website/content/Online Storage"
<Directory "/var/www/fixnode_website/content/Online Storage">
allow from all
Options +Indexes
</Directory>
SSLEngine on
ServerName storage.fixnode.ca
SSLCertificateFile /path/to/cert/storage.crt
SSLCertificateKeyFile /path/to/private key/private.key
</VirtualHost>
secure.fixnode.ca.conf
<VirtualHost *:443>
DocumentRoot "/var/www/fixnode_website/content/Secure Login"
<Directory "/var/www/fixnode_website/content/Secure Login">
allow from all
Options +FollowSymlinks
</Directory>
SSLEngine on
ServerName secure.fixnode.ca
SSLCertificateFile /path/to/cert/cert.crt
SSLCertificateKeyFile /path/to/cert/mykey.key
</VirtualHost>
and finally my virtual host for my root domain www.fixnode.ca.conf
<VirtualHost *:80>
DocumentRoot /var/www/fixnode_website
<Directory "/var/www/fixnode_website">
allow from all
Options +Indexes
</Directory>
ServerAlias fixnode.ca
ServerName www.fixnode.ca
</VirtualHost>
If you have recently made a change to your system, you may have overwritten your apache config file(e.g. httpd.conf or apache2.conf) which may reset the options to default.
You need to place this rule in both the sub-directories of both sub-domains:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(secure|storage)\. [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Resources