Rewrite not working, even though AllowOverride is set to All - .htaccess

I've installed LAMP stack on a digitalocean droplet running on Ubuntu. I have a file called "/restful/post.php".
using "https://url/restful/post.php" works just fine, however, I want to make it SEO friendly, sth like "/restful/post".
my htaccess is in the root folder "html/var/www" and has the following:
RewriteEngine on
RewriteRule ^/restful/post(.*)$ /restful/post.php?p=$1
I have got a2enmode enabled, AllowOverride is set to All in "/etc/sites-available/*".
for the 000-default.conf, I've got:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Redirect / https:/url
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
and for the 000-default-le-ssl.conf, I've got:
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
All the answers to the questions I've seen didn't fix my issue and I'm not really sure what I'm missing here.

Related

How is it possible to run 2 Websites in 2 different subfolders on one Apache instance?

i just want to run 2 web applications which both are in seperate subfolders.
So Subfolder One (which is the Homepage) should be reachable under : example.com.
While Subfolder two should be reachable under example.com/subfolder .
I know it is somehow possible with the Apache vhosts file, but i am new to this vhost stuff und dont know, how to solve that problem.
Thanks for your help!
i just got it running like that! Is there any reason this could be a problem in sight of security?
<VirtualHost *:80>
ServerName example.com
ServerAdmin example#mail.com
Redirect permanent / https://example.com
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
</Directory>
</VirtualHost>
**And for SSL**
<VirtualHost *:443>
ServerAdmin example#mail.com
ServerName example.com:443
<IfModule mod_headers.c>
Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
</IfModule>
DocumentRoot /var/www/webpage/
<Directory /var/www/webpage/>
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/webpage>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Alias /subfolder /var/www/subfolder/
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
SSLCertificateFile /etc/certs/live/**********/fullchain.pem
SSLCertificateKeyFile /etc/certs/live/**********/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

Htaccess doesn't work on MAMP with multiple sites

I have 3 sites on MAMP local server but in 2 of 3, the htaccess doesnt work.
I add this code in httpd.conf (MAMP->apache):
NameVirtualHost *
<VirtualHost *>
DocumentRoot "c:/MAMP/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\codes\Bedloop"
ServerName local.bed.com
</VirtualHost>
<VirtualHost *>
DocumentRoot "C:\codes\apart"
ServerName local.apart.com
</VirtualHost>
And this lines on windows hosts file:
127.0.0.1 local.bed.com
127.0.0.1 local.apart.com
I put on 3 pages, the same files (same page), but htacces only work on the localhost page, not in other 2. The main page work fine, but urls with rewrite rules fails.
I need to config something more?
Thx!
NameVirtualHost is deprecated. Can you try these directives in your Apache vhost file and restart apache:
<VirtualHost *:80>
ServerName localhost
DocumentRoot "c:\MAMP\htdocs"
<Directory "c:\MAMP\htdocs">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName local.bed.com
DocumentRoot "C:\codes\Bedloop"
<Directory "C:\codes\Bedloop">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName local.apart.com
DocumentRoot "C:\codes\apart"
<Directory "C:\codes\apart">
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride All
</Directory>
</VirtualHost>

VirtualHost does not work on my vps (ovh)

I am trying to peak my dimitri-dumont.fr domain name on my vps, however, it does not work.
I'm currently using apache2 and my vps is on ubuntu.
My domain name is pointing to the IP address of my vps (configured in A).
I created the site folder in /home/dimitri/html
After that, I did:
sudo chown -R dimitri /home/dimitri/html
sudo cmod -R 755 /home/dimitri/html
I create a dimitri-dumont.fr.conf file in /etc/apache2/sites-available and here is the content:
<VirtualHost *:80>
ServerAdmin contact#dimitri-dumont.fr
ServerName dimitri-dumont.fr
ServerAlias www.dimitri-dumont.fr
DocumentRoot /home/dimitri/html
#Redirect permanent / https://www.dimitri-dumont.fr
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/dimitri/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride None
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName dimitri-dumont.fr
ServerAlias www.dimitri-dumont.fr
ServerAdmin contact#imitri-dumont.fr
DocumentRoot /home/dimitri/html
<Directory /home/dimitri/html>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride none
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}access.log combined
</VirtualHost>
After that, i did :
sudo a2ensite dimitri-dumont.fr.conf
sudo service apache2 restart

Apache2 subdomain go to different folder

I want to subdomain use different folder. For example: example.com use /var/www/example and blog.example.com use /var/www/exampleblog.
Right now if I go to example.com or www.example.com the website loads correctly, but if I go to blog.example.com I got DNS_PROBE_FINISHED_NXDOMAIN.
The virtualhost files:
example.conf
<VirtualHost *:80>
DocumentRoot /var/www/example/
ServerName example.com
ServerAlias www.example.com
<Directory "/var/www/example/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/example-error
</VirtualHost>
And:
exampleblog.conf
<VirtualHost *:80>
DocumentRoot /var/www/exampleblog
ServerName blog.example.com
<Directory "/var/www/exampleblog/">
AllowOverride All
Options FollowSymLinks
</Directory>
ErrorLog /var/log/apache2/exampleblog-error
</VirtualHost>
What did I incorrectly?
The error was: The domain registrar isn't sent out the new settings when I wrote the question. They wrote, that it will be about 15-20 minutes, but somewhy it took more time.

htaccess with virtualhost not working

I have a local dev Debx64 machine with a number of virtualhosts configured.
the primary URL is set as
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName blah.com
ServerAlias blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
and that redirects to the primary operating VH
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>
I have a .htaccess set up on v1.blah.com to parse .html as .php
Options +ExecCGI
AddHandler php-fcgi .php .html
Action php-cgi /home/php5-fcgi
<FilesMatch "^php5?\.(ini|cgi)$">
Order Deny,Allow
Deny from All
Allow from env=REDIRECT_STATUS
</FilesMatch>
This works fine if I access the URL as v1.blah.com, however if I access it as blah.com the .htaccess is not invoked and the .html is served as normal.
What Am I missing? is there something in php.ini that needs to be changed?
Is there a particular reason why you need to have two separate entries for your hosts? Seeing as they both use the same Log Files, and DocumentRoot, could you not add blah.com to the list of ServerAlias' ?
So you would end up with the following configuration below:
<VirtualHost *:80>
ServerAdmin webmaster#blah.com
ServerName v1.blah.com
ServerAlias v1.blah.com blah.com
DocumentRoot /home/blah/v1.blah.com
<Directory /home/blah/v1.blah.com/>
AllowOverride All
Order allow,deny
allow from all
</Directory>
AccessFileName .htaccess
ErrorLog /home/blah/blah_logs/v1.blah.com.in-error_log
CustomLog /home/blah/blah_logs/v1.blah.com.in-access_log common
</VirtualHost>

Resources