Symfony - Use Apache ErrorDocument - apache

I want to replace symfony's Error template with apache ErrorDocument.
I have following conf:
<VirtualHost *:80>
ServerName localhost-de
ServerAdmin me#mydomain.com
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
ErrorDocument 404 /staticErrorPage.html
Order deny,allow
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /kontakt "/var/www/html/contact/web"
Alias /skin "/var/www/html/skin"
RewriteEngine on
RewriteRule ^/skin/(.{7})/(.*) /skin/$2
SetEnv locale de_DE
</VirtualHost>
My Symfony application is under "/var/www/html/contact/". When i enter a not existing page like "localhost-de/foo" i am getting the content of my html page.
But when i enter a not existing page like "localhost-de/kontakt/foo" i am always getting the content of symfony/twig page.
I know that i can override twig template but i dont want it this way. Any ideas how to handle this?

The ErrorDocument is used only for the Directory you specified. You should enclose ErrorDocument in a Location or LocationMatch directive. Read apache documentation for more details.

Related

Keep original URL after redirection by domain provider

Goal
fharrell.com/* is redirected by the domain provider to hbiostat.org/blog/*. I want to keep the address bar showing fharrell.com/*
Apache2 Setup
/etc/apache2/apache2.conf is standard with the following exception:
<Directory /home/ubuntu/htdocs/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/apache2/sites-enabled/hbiostat.org.conf is symbolically linked from /etc/apache2/sites-available/hbiostat.org.conf
hbiostat.org.conf sets the document root as /home/ubuntu/htdocs which has been working well for some time
Contents of hbiostat.org.conf:
<VirtualHost *:443>
ServerAdmin my#email.address
DocumentRoot /home/ubuntu/htdocs
ServerName hbiostat.org
ServerAlias www.hbiostat.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/ubuntu/htdocs>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hbiostat.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hbiostat.org/privkey.pem
</VirtualHost>
<VirtualHost *:80>
ServerName hbiostat.org
ServerAlias www.hbiostat.org
DocumentRoot /home/ubuntu/htdocs
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
</VirtualHost>
Systax was checked using sudo apachectl -t.
I checked that mod rewrite is active using sudo a2enmod rewrite and restarted the server with sudo systemctl restart apache2
But this has no effect, with hbiostat.org/blog/* remaining in the addressbar.
Tried:
Many remedies on stackoverflow.com (including the two below) and elsewhere, including putting the commands into an .htaccess file (I'd like to avoid the .htaccess approach).
Any help appreciated.
Redirect domain but keep original url
Redirect subfolder URL but keep original domain name
You can't make the browser display a different domain after a 30x redirect.
mod_rewrite doesn't do what you're thinking it does.

Default index.html page for any virtual host

I have configured some vhost like:
<VirtualHost *:443>
ServerName test.mywebsite.com
ServerAlias test.mywebsite.com
DocumentRoot /hosting/test
<Directory "/hosting/test">
AllowOverride All
Order Allow,Deny
Allow from All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /usr/local/apache/ssl/mywebsite.com.pem
SSLCertificateKeyFile /usr/local/apache/ssl/mywebsite.com.key
</VirtualHost>
Now i need to display a default webpage if domain root folder not have any index page like index.php or index.html.
Actualy if open wesite it return 403 forbidden if index.html/php is not present.
My idea is;
Folder site no index.html/php show:
defaultwebpage.html in /etc/var/http/hdocs/default.html
How to this?
Apache config.conf is configured with default root but if put the index.html here it is not displayed in case of lack.
DocumentRoot "/data/www/default"
<Directory "/data/www/default">
Couldn't you use the ErrorDocument thing to redirect all 404 to a certain default page? If that default page is outside your webroot use alias to bring it in.
So
Alias /specialindex /etc/var/http/hdocs/
and
ErrorDocument 403 /specialindex/default.html
Looks strange, but should work. But, catches all 403 of course...
The solution:
<LocationMatch "^/+$">
Options -Indexes
ErrorDocument 403 /.noindex.html
</LocationMatch>
<Directory /usr/share/httpd/noindex>
AllowOverride None
Require all granted
</Directory>
Alias /.noindex.html /usr/share/httpd/noindex/index.html

Adding blog to an existing website with the same domain name

I have a working website in Yii frame work with domainename.fr
Now i want to add a wordpress blog to be accessible in : domainename.fr/wp
I have tried to add a rewrite rule in the .htaccess file but it overrided by another rule that redirect every unknown path to the root (domainename.fr).
How can i do that with just alias, i mean to point /wp to /path_of_my_blog
my .conf file
<VirtualHost *:80>
ServerName domainename.fr
DocumentRoot /var/www/path/htdocs/src/web
<Directory /var/www/path/htdocs/src/web>
Options +Indexes
AllowOverride All
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
my blog path is /var/www/path/htdocs/wp

Apache virtual hosts without domain names, how to set a default site

I've set the following up to serve 2 development sites from the same box without using domain names:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /projecta /var/www/projecta
Alias /projectb /var/www/projectb
<Directory /var/www/>
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>
This works, but how do I direct requests for just the IP address, that is without a site name postfix, to a 'default' site?
You can use mod_rewrite to redirect to defult site.
RewriteEngine on
RewriteRule ^/$ /projecta [R]

ProxyPassMatch rule for Symfony 2.4

I am running Apache using mod_proxy_fcgi and PHP-FPM and am trying to get it to work Symfony. This is my first project using Symfony and am just getting a feel for it at the moment..
My vhost definition currently looks like:
<VirtualHost *:80>
ServerName symfony.dev
Documentroot "/vagrant/symfony/web"
DirectoryIndex app.php
ProxyTimeout 600
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:5090/vagrant/symfony/web/$1
<Directory "/vagrant/symfony/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
When I go to http://symfony.dev/app_dev.php/, the page loads, but all the links/paths include the full filesystem page. For example, the link for "Run the demo" is http://symblog.dev/vagrant/symfony/web/app_dev.php/demo/.
Is there a different ProxyPassMatch rule that would work, or a Symfony config that can compensate?
I tried ^/(.*\.php)(/.*)?$ which gets app_dev.php/ to load, but then app_dev.php/demo/ seems to load app_dev.php and not the demo, with broken paths to inline resources.
I had the same problems with ProxyPassMatch, but with and SetHandler everything works fine.
<VirtualHost *:80>
ServerName project.dev
ServerAlias www.project.dev
<FilesMatch \.php$>
SetHandler proxy:fcgi://127.0.0.1:9000
</FilesMatch>
#ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/project/web/$1
## Vhost docroot
DocumentRoot "/var/www/project/web"
## Directories, there should at least be a declaration for /var/www/awesome
<Directory "/var/www/project/web">
AllowOverride All
Order allow,deny
Allow from All
</Directory>
## Load additional static includes
## Logging
ErrorLog "/var/www/project/app/logs/apache2/error.log"
ServerSignature Off
CustomLog "/var/www/project/app/logs/apache2/access.log" combined
## SetEnv/SetEnvIf for environment variables
SetEnv APP_ENV dev
## Custom fragment
</VirtualHost>