apache rewrite on virtualhost won't work - apache

having problems to configure my apache virtualhost to work togheter with mod_rewrite. I have been enabling mod_rewrite a2enmod rewrite and I was creating the conf file for my virtualhost
ServerName wpa.myserver.com
ServerAdmin webmaster#localhost
DocumentRoot "/var/www/wordpress"
<Directory "/var/www/wordpress">
AllowOverride All
Options +FollowSymLinks
Order allow,deny
allow from all
</Directory>
On apache reload I'm getting error 500 and in my log file I'm getting the following
Invalid command 'Rewrite', perhaps misspelled or defined by a module not included...
htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Rewrite test.html index.html
</IfModule>
# END WordPress
PS. previously I was trying to use webmin to configure my virtualhost

Rewrite test.html index.html
Rewrite is not a valid statement.
You probably meant RewriteRule.

Related

Error when deploying cakephp application on ubuntu

Good morning,
I’m currently using Cakephp 3 version to develop an application. It should be online on an Ubuntu server and through the subdomain: http://etraining.minmap.cm
To do this, I configured a virtualHost, with the content :
<VirtualHost *:80>
ServerName etraining.minmap.cm
ServerAlias www.etraining.minmap.cm
ServerAdmin webmaster#localhost
DocumentRoot /var/www/etraining.minmap.cm/public_html/webroot
<Directory /var/www/etraining.minmap.cm/public_html/webroot>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The content of the .htaccess located at the application folder is:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
The content of the .htaccess located at webroot directory is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have followed all the configuration steps outlined in the official documentation.
mod_rewrite is enabled, mbstring and intl extensions are also enabled
But, I have 500 Internal Server Error:
This is the error reported in my Apache error.log:
I don’t know if I misconfigured Apache, my .htaccess files, and/or the config/app.php?
You should enable apache re-write module. It will work
"sudo a2enmod rewrite"
"sudo service apache2 restart"
Update .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

Vue.js Apache configuration with 301 https redirection (mode history)

I'm using vuejs with mode history enabled, and on the docs I find this Histoy mode docs
but then using Let's Encrypt with certbot I run a command to generate an ssl certificate, but now because of the redirection the following configuration no longer works.
<VirtualHost *:80>
ServerName virtuafest.vir.mx
ServerAdmin webmaster#localhost
DocumentRoot /var/www/virtuafest17/dist
<Directory /var/www/virtuafest17/dist>
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =virtuafest.vir.mx
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
How can I solve this without having to create an .htaccess file for the Rewrite conf?
Locate VirtualHost: *:443 in etc/apache2/apache2-le-ssl.conf and add your mod_rewrite there.

os x MAMP apache virtual host laravel project misconfigured

MAMP is installed in a MacBook. I use the MAMP apache.
Based on many online resources, I have done the following:
I added 127.0.0.1 my-site.local to file /etc/host.
I uncommented Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf in /Applications/MAMP/conf/apache/httpd.conf.
In /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf, I added
<VirtualHost *:80>
DocumentRoot "/Users/myname/laravel/mysite/public"
ServerName my-site.local
ServerAlias my-site.local
<Directory "/Users/myname/laravel/mysite/public">
DirectoryIndex index.php
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
In /Users/myname/laravel/mysite/.htaccess file:
<IfModule mod_rewrite.c>
Options +Indexes +FollowSymLinks +MultiViews
RewriteEngine On
#RewriteBase /
# Redirect Trailing Slashes If Not A Folder...
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Require all granted
</IfModule>
After all, localhost, localhost/MAMP, localhost/phpMyAdmin, all work, EXCEPT for my-site.local.
It shows 500 Internal server error. The server encountered an internal error or misconfiguration and was unable to complete your request.
Problem Solved!
Because the apache has been updated to apache2.2,
in the Applications/MAMP/conf/apache/extra/httpd-vhosts.conf,
change Require all granted to Satisfy Any.
That is it!
It took me two days to figure it out~

Fresh Laravel 5 shows 500 Internal Server Error no matter what (OS X, Apache)

My setup is OS X Yosemite, default Apache and PHP 5.6.
Vhost is set correctly, I have two other apps running ok:
<VirtualHost *:80>
ServerAdmin polar
ServerName lara5.com
ServerAlias lara5.com
DocumentRoot "/Users/polar/Sites/lara5/public"
ErrorLog "/private/var/log/apache2/dummy-host2.example.com-error_log"
CustomLog "/private/var/log/apache2/dummy-host2.example.com-access_log" common
</VirtualHost>
Hosts file is OK.
I've set the permissions to 777 to the whole project folder, still nothing.
If I remove .htaccess, the splash screen shows for the url lara5.com but the /home route returns 404.
I have tried both .htaccess (inside /public, ofc) Laravel provides, none of them work, 500 doesn't matter which route I access.
Default:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Other one from the docs:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Any ideas?
Thanks.
Translating comment into an answer to help out anyone else comes across this problem.
Based on your snippet from error.log it seems that Options directive isn't allowed in your .htaccess.
You can fix this error by commenting any line in your .htaccess starting from:
Options
To enable use of Options in .htaccess use:
Options All
in your Apace config's <Directory> section of your DocumentRoot.

Setting up Symfony2 to work with apache + php-fpm

How does one set up Symfony2 to work on Apache (Apache 2.4) combined with php-fpm?
The aim is to get rid of the .htaccess files and move everything into the apache config.
Without worrying about PHP-FPM, the config looks something like this:
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>
This thread is for me to post my own findings (and perhaps be corrected if I got it wrong!).
I prefer to just use ProxyPassMatch to make this work. By using this method, your rewrite rules in .htaccess don't need to be changed.
Here is my Apache2 vhost file:
<VirtualHost 192.168.100.51:80>
ServerName grae.labs.brainglove.com
ServerAlias www.grae.labs.brainglove.com
DocumentRoot /srv/symfony2/2.4.4/grae/web
DirectoryIndex app_dev.php
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/srv/symfony2/2.4.4/grae/web/$1
<Directory /srv/symfony2/2.4.4/grae/web>
AllowOverride All
Options FollowSymLinks
Require all granted
</Directory>
ErrorLog /var/log/httpd/grae.labs.brainglove.com_error.log
CustomLog /var/log/httpd/grae.labs.brainglove.com_access.log combined
The only line you need to add is the ProxyPassMatch. Everything else stays the same.
Don't forget to change the IP address and path to your symfony2 web directory.
To pass a request through to PHPFPM, the suggested RewriteRule was:
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2fto%2fwww.sock/%{REQUEST_FILENAME} [P,END]
Here's what I ended up. It seems to be working so far, but perhaps there's a better way?
<VirtualHost *:80>
ServerName mysymfonyproject.com
ServerAlias www.mysymfonyproject.com
ErrorLog /path/to/logs/mysymfonyproject_error.log
CustomLog /path/to/logs/mysymfonyproject_access.log combined
DocumentRoot "/path/to/sites/mysymfonyproject/web"
<Directory "/path/to/sites/mysymfonyproject/web">
AllowOverride None
Require all granted
## Start directives copied from standard Sf .htaccess
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} .*\.php
# Need to add the phpfpm call here so that php files (including app_dev.php) are passed to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
RewriteRule .? %{ENV:BASE}/app.php [L]
# The main phpfpm call is added at the end to pass php requests through to FPM
RewriteRule ^(.*\.php(/.*)?)$ fcgi://uds=%2fpath%2to%2fwww.sock/%{REQUEST_FILENAME} [P,END]
</IfModule>
## End directives copied from standard Sf .htaccess
</Directory>
</VirtualHost>