Getting 404 on a specific path /pricing with Apache server [migrated] - linux

This question was migrated from Stack Overflow because it can be answered on Server Fault.
Migrated 2 days ago.
I've set up an Apache server on Ubuntu 20.04
The site loads fine when I load the home page first (https://leadzilla.ai) and after that when I click on the pricing button and it takes me to https://leadzilla.ai/pricing and the that page loads fine as well.
But when I go directly to https://leadzilla.ai/pricing in the browser, I get a 404
Here is what I have in /etc/apache2/sites-available/leadzilla.ai.conf
<VirtualHost *:80>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =leadzilla.ai [OR]
RewriteCond %{SERVER_NAME} =www.leadzilla.ai
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I have this config in /etc/apache2/sites-available/leadzilla.ai-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /var/www/leadzilla.ai
ServerName leadzilla.ai
ServerAlias www.leadzilla.ai
<Directory /var/www/leadzilla.ai>
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Allow from all
#Deny from all
#Allow from 127.0.0.1
#Allow from ::1
</Directory>
<Directory /var/www/leadzilla.ai/blog>
AllowOverride All
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/leadzilla.ai/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/leadzilla.ai/privkey.pem
</VirtualHost>
</IfModule>
I have Wordpress on https://leadzilla.ai/blog so that has to be taken care of as well.
Here is what I have tried:
RewriteRule ^pricing$ pricing.html [NC]
I added it before the other rewrite rule but that doesn't seem to be working. Any ideas?
[EDIT]
This is solved now. The issue was a Next.js config, not an Apache config.
I put in exportTrailingSlash: true in my module.exports and it worked

I find this to be curious behavior. But if you have a RewriteRule in the <VirtualHost *:443>, then you should also have RewriteEngine On.
Are there any symbolic links in your directory at all. Anything like foo -> foo.html?
Are there any directories like /var/www/html/pricing/ in your directory structure?
Also, remember, that all of your traffic ends up on HTTPS, which means that only the <VirtualHost *:443> is in play. The other virtual host entry only is used long enough to redirect from HTTP to HTTPS. Any rewrite rules for the :80 VirtualHost do not apply on HTTPS.

Related

You configured HTTPS(443) on the standard HTTP(80) port

In my apache error logs, I have bunch of ssl warnings saving You configured HTTPS(443) on the standard HTTP(80) port!
Here is my site.ca.conf file
<VirtualHost *:80>
ServerName site.ca:80
DocumentRoot "/var/www/site/public"
<Directory "/var/www/site/public">
AllowOverride all
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site.ca
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
and here is my site.ca-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site.ca:80
DocumentRoot "/var/www/site/public"
<Directory "/var/www/site/public">
AllowOverride all
</Directory>
ServerAlias site.ca
SSLCertificateFile /etc/letsencrypt/live/site.ca/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site.ca/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Every thing works fine. I am not sure why this warning shows up every day in my apache log files, and how can I resolve it?
Generally, this is because you do not have any SSL configuration on the virtual host on port 443. You may need to enable "SSLEngine on" and provide certificate information. The warning indicates are serving regular HTTP traffic on what is usually an HTTPS port.
In these config files listed by the requester, there are some tweaks/corrections to be done:
we don't need to have a DocumentRoot in the site.ca.conf because we will redirect HTTP to the HTTPS (site.ca-le-ssl.conf)
the ServerName directive shouldn't have a port number, instead it should be in the VirtualHost level
the ServerName and ServerAlias should be near to each other and there should be www.site.ca as an Alias too in both files to handle the requests containing the www
in site.ca-le-ssl.conf file there is a ServerName site.ca:80 and that's not correct (there should be no port number)
there must be a SSLEngine on in the site.ca-le-ssl.conf
I hope that help someone even this is an old question

Configuring symfony and apache

I'm learning symfony right now. I want to use apache webserver instead of the shipped php. How can I add a virtualhost if I want to use also the default localhost? (localhost:80 for my notebook and I have a "personalhomepage")
Here is one of the vHosts I am currently using (cronolog is used for log rotation):
<VirtualHost *:80>
ServerName projectname.dev
DocumentRoot /var/www/projectname/html/web
<Directory /var/www/projectname/html/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog "|/usr/bin/cronolog /var/www/projectname/log/%Y-%m/error_%d_%m_%Y.log"
CustomLog "|/usr/bin/cronolog /var/www/projectname/log/%Y-%m/access_%d_%m_%Y.log" combined
</VirtualHost>
For testing and development purposes I usually create a local domain with the .dev or .local ending in the hosts file, e.g.:
127.0.0.1 projectname.dev
Make sure the domain name corresponds with the one in the vHost config. Oh, and don't dont forget to restart apache. Hope this helps.
Using these steps, you can use either projectname.dev, projectname.dev/app_dev.php or you set the vHost's DirectoryIndex directly, if you want to always use app_dev.php:
<Directory /var/www/projectname/html/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex app_dev.php
</Directory>
You would setup Apache in the same way as any other webservers that have more than one site on them - ideally, a named vhost. Symfony has an example Apache vhost config,
<VirtualHost *:80>
ServerName domain.tld
ServerAlias www.domain.tld
ServerAlias www.sitename.127.1.0.1.xip.name
DocumentRoot /var/www/project/web
<Directory /var/www/project/web>
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
# In local development, I default this to app_dev.php
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
In this example, domain.tld (or www.) is the name you would use to reach the site. You would have to be able to reach those names via DNS though - on your local machine, 127.0.0.1. There are also some 'wildcard DNS' services that may help, such as http://xip.name/ With services such as these, you could put ServerName sitename.127.1.0.1.xip.name into the above configuration and then use that to reach your site.
I do something similar myself with a wildcard DNS sub-domain I own for a local machine. I have a number of such Apache Vhost configurations setup.

WAMP ignoring rewrite rules in .htaccess

I'm having trouble getting mod_rewrite to behave properly on WAMP after upgrading to PHP 7.0.0. All RewriteRules seem to be completely ignored by Apache. They result in 404 errors.
This is my virtual host in httpd-vhosts.conf:
<VirtualHost *:80>
ServerName myproject.local
DocumentRoot "D:/Projects/myproject/www"
ErrorLog "D:/Projects/myproject/www/apache_errors.log"
LogLevel info
<Directory "D:/Projects/myproject/www/">
LogLevel debug
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
This is my .htaccess, which is recognized by Apache, will handle directives like DirectoryIndex, but seems to ignore any RewriteRules:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z_\-\s]+)/?$ $1.php [L,QSA] #root pages
RewriteRule ^([a-zA-Z_\-\s]+)/([a-zA-Z_\-\s]+)/?$ core/modules/$1/$2.php [L,QSA] #pages with no id
RewriteRule ^([a-zA-Z_\-\s]+)/([a-zA-Z_\-\s]+)/([0-9]+)/?$ core/modules/$1/$2.php?$1_id=$3 [L,QSA] #pages with id (edit, etc)
My apache error log shows nothing of consequence: just that request fails:
[Sun Dec 18 15:47:03.787934 2016] [core:info] [pid 12532:tid 1140] [client ::1:57506] AH00128: File does not exist: D:/Projects/StoryTracker-Core/www/test
There must be some outside force I'm not aware of causing these results.
EDIT
I've updated my virtual host as follows to no avail:
<VirtualHost *:80>
ServerName myproject.local
DocumentRoot "d:/projects/myproject/www"
ErrorLog "d:/projects/myproject/www/apache_errors.log"
LogLevel trace8
<Directory "d:/projects/myproject/www/">
Options +Indexes +FollowSymLinks +Includes
AllowOverride All
Require all granted
LogLevel trace8
</Directory>
</VirtualHost>
mod_rewrite did not like dashes in my project directory name.
After renaming directories in my project path away from using -, I was able to figure out the rest of the issues from LogLevel debug rewrite:trace8.

Apache2, re-direct blank.example.com to example.com/blank/blank

I'm having issues with this re-direct. I've tried the .htaccess method with RewriteRule and RewriteCond, as well as the VirtualDirectory method. Here's what I've tried for VirtualHost:
<VirtualHost *:80>
ServerName blank.example.com
Redirect permanent / "http://example.com/blank/blank"
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAdmin webmaster#localhost
DocumentRoot /the/doc/root
# 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>
and this for .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blank.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/blank/blank [R=301,L]
I'm not sure if it's needed or not, but blank.example.com is also pointed to localhost in /etc/hosts
Any tips on what I'm missing?
Here are a couple of things.
If you are wanting to just have a subdomain with it's own document root then your vhost needs to look like this. Then there is no need to redirect.
<VirtualHost *:80>
ServerName blank.example.com
DocumentRoot /path/to/blank/blank
<Directory /path/to/blank/blank>
#enable .htaccess for this subdomain
AllowOverride All
</Directory>
</VirtualHost>
If you are truly wanting to redirect your subdomain to the main domain.
Then remove this first vhost. it's not needed at all.
#This virtualhost is not needed
<VirtualHost *:80>
ServerName blank.example.com
Redirect permanent / "http://example.com/blank/blank"
</VirtualHost>
Then on your main VirtualHost add a server alias like so
ServerName example.com
ServerAlias blank.example.com
ServerAdmin webmaster#localhost
DocumentRoot /the/doc/root
<Directory /the/doc/root>
#enable .htaccess for this main domain
AllowOverride All
</Directory>
Then for your .htaccess rules
RewriteEngine on
RewriteCond %{HTTP_HOST} ^blank\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/blank/blank/$1 [R=301,L]
Restart Apache after all config file changes.

Webpage has a redirect loop www to non-www

I installed lamp on debian 7 but i need a non-www url now my website always add www. before
ServerAdmin webmaster#localhost
ServerName www.example.com (the same issu with example.com)
ServerAlias example.com *.example.com
DocumentRoot /home/site/www
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /home/site/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
I test with htaccess too but browser give me loop
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
Why apache add www ? Its new configuration i have just enable one site.
Thanks
Make sure that the domain example.com actually resolves via DNS
(and not just www.example.com)
Modern browsers (and not-so-modern browsers as well) will try to auto-correct the domain if they cannot resolve it.
Among other things this means that they will try to prepend www. to the domain-name.

Resources