REQUEST_FILENAME issues, stopped functioning with php upgrade - .htaccess

So I have a request_filename rule which has suddenly stopped working. I have recently upgraded my server to Jessie, and php upgraded with it.
However, this is the rewrite rule I have at the moment.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.URL\.com$
RewriteRule ^/?$ "http\:\/\/URL\.com\/" [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.URL.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ $1.html
RewriteRule ^(.*)/$ $1 [NC,L]
The .htaccess file is owned by www-data and can be accessed.
I seem to see this in the error logs
[Thu Jun 04 19:43:21.641790 2015] [authz_core:debug] [pid 15423] mod_authz_core.c(809): [client 213.138.113.36:65331] AH01626: authorization result of Require all granted: granted, referer: http://www.URL.com/
[Thu Jun 04 19:43:21.641883 2015] [authz_core:debug] [pid 15423] mod_authz_core.c(809): [client 213.138.113.36:65331] AH01626: authorization result of <RequireAny>: granted, referer: http://www.URL.com/
[Thu Jun 04 19:43:21.642056 2015] [core:info] [pid 15423] [client 213.138.113.36:65331] AH00128: File does not exist: /var/www/URL/about, referer: http://www.URL.com/
Is it perhaps something I am not loading in my virtual host conf?
<VirtualHost *:80>
ServerAdmin EMAIL#hotmail.com
ServerName URL.com
ServerAlias www.URL.com
ServerAlias *.URL.com
SetEnv APPLICATION_ENV dev
DocumentRoot /var/www/URL
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}/URL.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/URL.access.log combined
</VirtualHost>
This is a website I took over hosting, I don't usually work with .htaccess files. Any advice would be appreciated.
The issue I have is the pages try to load as www.url.com/about This fails as the file is about.html.

I see a few things going on here. I don't see a Directory Directive for the actually document root. Which then would not be using the .htaccess file because there is no AllowOverride All specified for your document root. Also you shouldn't use 2.2 directives in 2.4. Change your Vhost file to look like this. I modified it slighty and added the directory Directive for your root.
<VirtualHost *:80>
ServerAdmin EMAIL#hotmail.com
ServerName URL.com
ServerAlias *.URL.com
SetEnv APPLICATION_ENV dev
DocumentRoot /var/www/URL
<Directory "/var/www/URL">
Options -Indexes -MultiViews
AllowOverride All
Require all granted
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride All
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/URL.error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel debug
CustomLog ${APACHE_LOG_DIR}/URL.access.log combined
</VirtualHost>

The issue was the my main apache2.conf file.
AllowOveride was disabled.
I made the following change
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

Related

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

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.

CodeIgniter 3 not working on LAMP

I have CodeIgniter 3 running locally on MAMP just fine. But, when I pull from my repo and try to set it up on an ec2 instance with LAMP installed, I get a 404. CodeIgniter is in the /var/www/html folder
My /etc/apache2/apache2.conf file contains the following:
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
mod_rewrite is enabled. The file /etc/apache2/sites-available/000-default.conf is as follows:
<VirtualHost *:80>
AccessFileName .htaccess
ServerAdmin admin#yourdomain.com
DocumentRoot /var/www/html/
<Directory />
AllowOverride All
Order allow,deny
allow from all
</Directory>
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The file /var/www/html/application/config/config.php has the following settings:
$config['index_page'] = '';
$config['base_url'] = 'http://baseurl.com';
My .htaccess file is as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
first you check the server configuration. you can use apache error log to find server related issue.
then check error log of application.
In database.php check the
'dbdriver' => 'mysqli',
because newest Lamp not supported
'dbdriver' => 'mysql',

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.

URL rewrite for admin exclude directory

I have a URL rewrite setup to create nice URLs
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin\/assets|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
When I access the admin area with /admin the URL is rewritten as /admin/?rq=admin because I have a root level directory named "admin". It's probably pretty simple, but how can I edit (or add to) my .htaccess rules so that the url is written cleanly as /admin/
UPDATE:
To clarify, I want to access /admin using /index.php?rq=admin and not by calling the /admin/index.php
Here is my apache virtualhost config:
<VirtualHost *:80>
ServerAdmin alex
ServerName hub
ServerAlias hub
DocumentRoot /var/www/hub/
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/hub>
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 None
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
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
Just add the admin folder to the list of exceptions in your RewriteCond. Now, you have exception for admin/assets so you can delete the assets part and leave the exception for the whole admin folder like this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^\/*(index\.php|blog|admin|site\/assets|robots.txt|sitemap.xml|products.xml|favicon\.ico)
RewriteRule ^(.*)$ /index.php?rq=$1 [L,QSA]
It seems that added DirectorySlash Off in my .htaccess did the trick. Not sure if this is the correct workaround but it solved my particular problem. I had to make sure to clear my cache fully to prevent cached redirects (thanks Kamil)
In Chrome: Chrome-> Tools -> Clear Browsing Data -> Empty the Cache

Resources