Apache2 mod_rewrite not fetching .htaccess - apache

Using a fresh install of Ubuntu 18.04 with Apache2 (using virtual hosts), however I cannot get .htaccess to rewrite my URL as needs be.
Consider:
000-default.conf:
<VirtualHost *:80>
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
allow from all
</Directory>
ServerName mydomain.com
ServerAlias www.mydomain.com mydomain.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/radio/
</VirtualHost>
.htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA,L]
Any help is much appreciated :)

Related

Redirect ip address to https server name

So this is my conf:
<VirtualHost *:80>
<Directory /var/www/html/webserver/public>
Allow From All
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www/html/webserver/public
ServerName ./install.sh
</VirtualHost>
<VirtualHost *:80>
<Directory /var/www/html/webserver/public>
Allow From All
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www/html/webserver/public
ServerName test.com
ServerAlias www.test.com
Redirect permanent / https://test.com/
RewriteEngine on
#RewriteBase /
RewriteCond %{SERVER_NAME} =www.test.com [OR]
RewriteCond %{SERVER_NAME} =test.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<IfModule mod_ssl.c>
<VirtualHost *:443>
<Directory /var/www/html/webserver/public>
Allow From All
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www/html/webserver/public
ServerName test.com
ServerAlias www.test.com
SSLCertificateFile /etc/letsencrypt/live/test.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/test.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
This works perfectly for http -> https redirection. For example test.com or http://test.com redirects to https://test.com. www.test.com does not work (I don't know why?), I'll get a 404 page. Next big thing, lets assume the ip of my webserver is 12.23.45.67 - how do I have to change my config file, so this ip also redirects to https://test.com?
new .conf file based on #Don't Panic post:
<VirtualHost *:80>
<Directory /var/www/html/webserver/public>
Allow From All
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www/html/webserver/public
ServerName test.com
ServerAlias www.test.com
RewriteEngine on
#RewriteBase /
RewriteCond %{SERVER_NAME} =www.test.com [OR]
RewriteCond %{SERVER_NAME} =test.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerName XX.XX.XX.XX
ServerAlias www.test.com
DocumentRoot /var/www/html/webserver/public
RewriteEngine on
RewriteCond %{SERVER_NAME} =test.com [OR]
RewriteCond %{SERVER_NAME} =www.test.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
So my final solution looks like this:
<VirtualHost *:80>
<Directory /var/www/html/webserver/public>
Allow From All
AllowOverride All
Options -Indexes
</Directory>
DocumentRoot /var/www/html/webserver/public
Redirect / https://test.com
</VirtualHost>
This is working for nearly every redirection, but it's not working for www.test.com - Is this a good solution? May not. But it's kind of a working one.

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>

Redirect all unknown domains

I want to redirect all unknown subdomains in apache, can you help me ? Exemple : " aaa.mydomain.com / bbb.mydomain.com / ccc.mydomain.com " redirect to " all.domain.com ".
My current host :
>
ServerAdmin me#gmail.com
ServerName domain.dev
ServerAlias administration.domain.dev
ServerAlias agence.domain.dev
ServerAlias css.domain.dev
ServerAlias dev.domain.dev
ServerAlias dome.domain.dev
DocumentRoot /var/www/symfony/domain/web
<Directory /var/www/symfony/domain/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error_dev.domain.dev.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access_dev.domain.dev.log combined
You can do this with a reverse proxy, look at apache proxypass

Unable to configure .htcaccess with Apache2

I have been trying, for the good part of two hours, to configure apache2 to use .htcaccess.
Here's my configuration file:
<VirtualHost *:80>
ServerAdmin MY_EMAIL
DocumentRoot /var/www/MY_DOMAIN/public_html
ServerName MY_DOMAIN
ServerAlias www.MY_DOMAIN
Header set Access-Control-Allow-Origin "*"
<Directory /var/www/MY_DOMAIN/public_html>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName SUB_DOMAIN.MY_DOMAIN
DocumentRoot /var/www/MY_DOMAIN/SUB_DOMAIN
<Directory /var/www/MY_DOMAIN/SUB_DOMAIN>
AllowOverride All
</Directory>
</VirtualHost>
And here is my .htcaccess (located in /var/www/MY_DOMAIN/public_html/.htcaccess):
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
If I visit MY_DOMAIN/header, I receive a 404 Error. However, MY_DOMAIN/header.php works fine.
How can I fix this? Thanks!
Are you naming the file ".htaccess" or ".htcaccess"
If you are not naming the file properly, that is probably the problem.
I think you're looking for ".htaccess"