My domain gives 301 moved permanently, eventually loads or doesn't load my Apache server - apache

I have an Apache server, where the root website directory is located at /var/www/html/. I have a domain I purchased on GoDaddy that contains an # A record which points to my home IP Address where my server is located. On the server end, I have a private folder inside my website directory protected correctly with a username and password, as you'll see in my server configuration. I noticed that when I go to my domain with Chrome, sometimes it will load instantly, and other times (according to the Google Chrome Developer Network Console) I will keep getting a "301 Moved Permanently" status code from my server. Is there something I am overlooking?
My website conf file (replaced with example.com for temporary privacy):
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.example.com
ServerAlias example.com
ServerAdmin example#example.com
DocumentRoot /var/www/html
ErrorDocument 404 /404.html
<Directory "/var/www/html/private">
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
And here is the .htaccess file located at the root of my website, which might help:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule ^/(.*)$ http://www.example.com/$1 [L,R=301]

I finally found a working solution. It wasn't the server's fault, it was the way I set up GoDaddy. Inside your domain's DNS settings, have the server permanently redirect to your public IP address. Ensure it is a masked redirection so that your domain stays in the web address bar.

Related

Routing problem on my Symfony project on Apache

I looked at different topic regarding my problem but it still doesn't work.
I have just deployed my website in Symfony, on my Debian with Apache.
I manage to go to the main page, but the others return me a 404 error.
I saw that it was necessary to add the .htaccess file for the routing, something that I did but it still does not work.
But when I enter the url: https://myWebsite/index.php/movie it works.
(Tell me if you need more code)
EDIT : on the url https://myWebsite.fr the Symfony Tool Bar doesnt work, the error in the console is : https://mywebsite.fr/_wdt/af9d59
RESOLVED : I added the allowoverride in my HTTPS .conf and its working.
There is my website.conf on my Apache folder "sites-available" :
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName mywebsite.fr
ServerAdmin webmaster#localhost
DocumentRoot /var/www/project/public
<Directory /var/www/project/public>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/project_error.log
CustomLog ${APACHE_LOG_DIR}/projec_access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =mywebsite.fr
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My second .conf mywebsite-le-ssl for the https (using certbot) :
`
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName mywebsite.fr
ServerAdmin webmaster#localhost
DocumentRoot /var/www/mywebsite/public
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/project_error.log
CustomLog ${APACHE_LOG_DIR}/projec_access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =mywebsite.fr
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/mywebsite.fr/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mywebsite.fr/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
`

virtual host config file not redirecting http to https

I have the problem of redirecting the http to https but all the information/tutorials and descriptions are not working. We are using Apache2 on a Debian machine and this is the conf file
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
ServerName assets.xxx.it
ServerAlias assets.xxx.it
DocumentRoot /var/www/assets/eit_resource_manager_frontend/build
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RedirectMatch ^(.*)$ https://assets.xxx.it$1
</VirtualHost>
<VirtualHost *:443>
ServerName assets.xxx.it
ServerAlias assets.xxx.it
Protocols h2 http/1.1
<Directory "/var/www/assets/eit_resource_manager_frontend/build">
RewriteEngine on
#Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
#Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.theml [L]
</Directory>
# SSL Configuration
# Other Apache Configuration
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/assets.xxx.it/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/assets.xxx.it/privkey.pem
</VirtualHost>
After any change in the file I restart the server but the HTTP is not redirected to HTTPS. I have tried different implementation with same poor result.
For further information, the login page is on assets.xxx.it/login and the redirect from "/" to "/login" is handled inside the app (via React Router)
Any suggestions?
When creating the SSL certificate with certbot and the Apache plugin, a SSL config file was created, so we came up with having a file for vh 80 created by us, a file for vh 443 created by us, and a file for both 80 and 443 generated while creating the certificate.
As said, this file had instructions for both port 80 and 443 but, despite the fact that we asked for the redirect while creating the certificate, there was not such an instruction in this conf file. So we added the RedirectMatch instruction and it worked. We also deleted the vh 443 conf file that we had created and it went on working.
After other search I have also understood that the RewriteCond and RewriteRule in the Directory tag are just there if you want to use the .htaccess file in the repo folder for a more grained control.

Different landing pages for the same domain VPS

I have a self-managed VPS server with no control panel running Ubuntu. I managed to point my domain to the server successfully. Then I installed apache2. I created an index landing page in directory:
var/www/gci/
By default system created another directory with default index landing page:
var/www/html/
Then I edited the gci.conf under directory:
/etc/apache2/sites-available/
to include the following lines:
ServerAdmin myemail
DocumentRoot /var/www/html
ServerName burooq.com
The whole file contents is as follows:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin myemail
DocumentRoot /var/www/html
ServerName burooq.com
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My issue is basically, when I access my domain using http://Burooq.com, it lands on the index page under gci folder. However, when I use https://Burooq.com, it lands on the index page under html folder. How is that possible and how would I point both request to one landing page.

IP Address showing instead of Domain apache server

I just purchased a domain from GoDaddy, let's call it example.com. I set up my A record and CNAME to properly point to my home IP address (see picture below) where I run an Apache2 server on my Raspberry Pi.
My 000-default.conf file is as follows:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorDocument 404 /404.html
<Directory "/var/www/html">
AllowOverride All
Options All
Require all granted
# Any other directives
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
I have searched the internet for hours and even asked another question on StackOverflow to where I thought the problem was resolved, however after about an hour of restarting the Apache2 service on the Raspberry Pi, it goes back to showing my home IP Address in the address bar instead of my newly purchased domain. I have tried restarting the service multiple times but I always end up with the same result. Flushing DNS on my devices does nothing, too. How can I make it so that it always shows my domain in the address bar?
Make sure that in your Domain provider (GoDaddy for example) that you aren't forwarding to your IP address. Instead, forward to your domain.

Is it possible to use the same dns for 2 webapps

I'm currently in the process of configuring 2 third party apps for a game called EVE Online, one of them is Pathfinder and the other is a corporation management app.
for example if I want to access Pathfinder my URL would be "mydomain.com/pathfinder", but if wanted to access the other app my URL would be "mydomain.com/otherapp".
Pathfinder is located in the DocumentRoot folder (/var/www/pathfinder) and the other app should be in the Document Root folder aswell (/var/www/otherapp)
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName mydomain.com
ServerAdmin admin#bfc.com
DocumentRoot /var/www/pathfinder
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet