Problem enabling .htaccess - apache

I'm trying to enable .htaccess files on a Ubuntu server I set up. I changed the sites file from:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
[unnecessary config code omitted]
</VirtualHost>
to
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/document_root
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/document_root>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
[unnecessary config code omitted]
</VirtualHost>
Now when I try to view a page in my browser I get a 500 Internal Server Error. Any ideas as to what my problem may be? Thanks for the help.
EDIT
Here is my .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
I checked the apache error logs as requested and it appears that the error being logged is:
[Fri Jul 10 19:39:12 2009] [alert]
[client 192.168.1.1]
/var/www/document_root/.htaccess:
Invalid command 'RewriteEngine',
perhaps misspelled or defined by a
module not included in the server
configuration

Bah... I didn't have mod_rewrite enabled. I feel stupid.

Related

cannot access url string something missing on my code?

I have a problem with apache giving me a "not found" error.
scenario:
I have a url of the form --> 10.17.10.19/webapps/api/index.php?url=auth
I want to rewrite the url in the form --> 10.17.10.19/webapps/api/auth
im Using Ubuntu 20.04 apache2
vhost:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
htaccess:
RewriteEngine On
Options All -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
apache.conf
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>
<Directory /var/www/>
Options Indexes
# FollowSymLinks
# AllowOverride None
Require all granted
</Directory>
#<Directory /srv/>
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
Please help me to correct the condition to recognize the parameter
i found the answer
i need to enable header so the htaccess can work
ae2enmod header
https://httpd.apache.org/docs/2.4/mod/

Prevent Apache for opening files with similar name to url

My .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUESTFILENAME} !-f
RewriteCond %{REQUESTFILENAME} !-d
RewriteRule ^login/generic_oauth$ auth0-callback.php [L]
RewriteRule ^(.*)$ index.php?page=$1 [L]
My vhost file:
<VirtualHost *:443>
DocumentRoot /home/blabla/www/frontend/
ServerName some-domain.net
ServerAlias www.some-domain.net
SSLEngine on
SSLCertificateFile /etc/apache2/crt/cert.pem
SSLCertificateKeyFile /etc/apache2/crt/key.pem
<Directory />
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
<Directory /home/blabla/www/>
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The problem is when I try to access https://www.some-domain.net/login/generic_oauth Apache is loading login.php (which exists). Problem disappears when I rename the file to loggin.php for example.
The problem is when I try to access https://www.some-domain.net/login/generic_oauth Apache is loading login.php (which exists). Problem disappears when I rename the file to loggin.php for example.
This problem is symptomatic of having MultiViews enabled. Although, you appear to be disabling MultiViews in the server config, except that you are not targeting the DocumentRoot with your <Directory> containers...
DocumentRoot /home/blabla/www/frontend/
:
<Directory />
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
<Directory /home/blabla/www/>
Options -Indexes +FollowSymLinks -MultiViews
AllowOverride All
Require all granted
</Directory>
You should not be setting AllowOveride All and Require all granted in the <Directory /> container, ie. the entire drive! You should be disabling access instead and this should already be defined outside of the <VirtualHost> container, in the main server config.
You are then granting access to /home/blabla/www/, but this is the directory above the DocumentRoot?! Do you have another .htaccess in this parent directory? Do you have another <Directory> container that matches the DocumentRoot?
So, your config should look more like this:
<Directory />
Options SymLinksIfOwnerMatch
AllowOverride None
Require all denied
</Directory>
<VirtualHost *:443>
ServerName some-domain.net
ServerAlias www.some-domain.net
SSLEngine on
SSLCertificateFile /etc/apache2/crt/cert.pem
SSLCertificateKeyFile /etc/apache2/crt/key.pem
DocumentRoot /home/blabla/www/frontend/
<Directory /home/blabla/www/frontend>
Options +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
As with any changes to the server config, you need to restart Apache.
If this does not resolve the issue then you need to look for any other places in the config that could be enabling MultiViews. And if all else fails, explicitly disable MultiViews in the .htaccess file itself:
Options -MultiViews

Redirect using apache conf file 404 error

I have a beta wordpress site (beta.domain.co.uk) I would like to redirect to (domain.co.uk).
I have a .conf file for each site pointing to its folder with the wordpress files.
I have tried just renaming the folders but I get a 404 error.
How can I point the beta site to my main site?
main site conf :
<VirtualHost *:80>
ServerName www.domain.co.uk
DocumentRoot /var/www/domain.co.uk
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/domain.co.uk/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domain.co.uk
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.co.uk
RewriteRule ^/(.*)$ http://www.domain.co.uk/$1 [L,R=301]
</VirtualHost>
beta site conf:
<VirtualHost *:80>
ServerName beta.domain.co.uk
DocumentRoot /var/www/beta.domain.co.uk
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/beta.domain.co.uk/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
</VirtualHost>
Use the following rewrite rules, make sure you put it inside the beta site conf, inside virtualhost.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beta\.domain\.co\.uk$
RewriteRule ^(.*)$ http://domain.co.uk/$1 [R=301,L]

problem in configuration laravel5.7 in centos7

I have Internal Server Error (error 500):
[client 5.211.29.235:10910] /home/..../public_html/public/.htaccess: Options not allowed here
mysite.conf:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias mywebsite.com *.mywebsite.com
DocumentRoot /home/..../public_html/public/
ErrorLog /home/..../public/error_log
</VirtualHost>
Changing permission to read-write file(755) did not work.
Disable SELinux did not help.
Changing .httaccess also did not help.
changing httpd.conf did not help too.
<Directory />
AllowOverride ALL
</Directory>
or
<Directory "/var/www">
Options Indexes FollowSymLinks MultiViews
AllowOverride Options
Order allow,deny
allow from all
</Directory>
change .htaccess did not work:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
problem solved by changing mysite.conf file to this:
<VirtualHost *:80>
ServerName mywebsite.com
ServerAlias mywebsite.com *.mywebsite.com
<Directory />
AllowOverride ALL
</Directory>
DocumentRoot /home/..../public_html/public/
ErrorLog /home/..../public/error_log
</VirtualHost>

Ubuntu Apache virtualhost with symfony

have a problem here with Symfony . I want to have virtual host on ubuntu so I can access my Symfony application like this app.local. What I have tried:
<VirtualHost *:80>
ServerName app.local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
DocumentRoot /var/www/app/web
<Directory /var/www/app/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
</VirtualHost>
I added these lines to hosts file
127.0.0.1 app.local
but when I write app.local in my browser, it brings the index of my www directory(default apache page). What am I doing wrong?
Try this :
/etc/apache2/sites-available/mysite.conf
<VirtualHost *:80>
ServerName app.local
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>
DocumentRoot /var/www/app/web
<Directory /var/www/app/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Then apply configuration changes :
$>sudo a2ensite mysite // If not already enabled
$>sudo service apache2 restart
If the problem is not solved, check the error logs in /var/log/apache2/