Hi, I use these rules in .htaccess and they work perfect. However, they do not work in Options / Apache Directives. Code: <IfModule mod_rewrite.c> # Start Rewrite Engine RewriteEngine On RewriteBase / Options +FollowSymLinks # Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ /$1 [L] # Remove .php extension RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^\.]+)$ $1.php [L] # Remove .html extension RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^([^\.]+)$ $1.html [L] </IfModule> Can you help me getting them to work? I use Ubuntu 18.04. Thanks!
Ok, I finally got them to work, but now my problem is that they only work with Mod-PHP. Code: <Directory {DOCROOT}> <IfModule mod_core.c> AllowOverride All Options +FollowSymLinks </IfModule> <IfModule mod_rewrite.c> # Start Rewrite Engine RewriteEngine On RewriteBase / # Remove trailing slash RewriteCond %{REQUEST_URI} !-d RewriteRule ^(.*)/$ /$1 [R,L] # Remove need for ".php" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^\.]+)$ $1.php [L] # Remove need for ".html" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^([^\.]+)$ $1.html [L] </IfModule> </Directory>
Theey work with mod_php only as you limited them to work with mod_php only. You have to remove the IfModiule lines.
Unfortunately they still don't work if I remove the IfModule lines. I use vhost.conf.master from master branch and did a resync afterwards.
That's what I already do. The reason I use vhost.conf.master is that I had this issue: https://www.howtoforge.com/community/threads/issue-with-non-existent-php-files.77589/
But you can not use a placeholder {DOCROOT} in vhost.conf.master. It simply does not exist there. BTW, normally one puts rewrite rules just in a .htaccess file on apache servers. Create a file named .htaccess in the web folder of the website and there you add: Code: AllowOverride All Options +FollowSymLinks # Start Rewrite Engine RewriteEngine On RewriteBase / # Remove trailing slash RewriteCond %{REQUEST_URI} !-d RewriteRule ^(.*)/$ /$1 [R,L] # Remove need for ".php" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^\.]+)$ $1.php [L] # Remove need for ".html" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^([^\.]+)$ $1.html [L]
I have not put anything custom in vhost.conf.master. I mention I use the master branch version because there could be changes in it that causes the issue. It is on the 3.1.13 milestone to backport it. I already have success with using .htaccess as I wrote in the OP. I just try to optimize my server for speed, as .htaccess adds overhead and I have a lot of sites with this configuration.
Hi @till and thank you for trying to help me. I have almost solved the issue. It had nothing to do with the php-modes. First of all I think these parts of vhost.conf.master Code: <If "-f %{DOCUMENT_ROOT} . '/' . %{REQUEST_URI}"> should be replaced with Code: <If "-f %{SCRIPT_FILENAME}"> This article here is describing it in more detail: http://lost.l-w.ca/0x05/apache-mod_proxy_fcgi-and-php-fpm/ It makes it possible to archieve my goal with the following: Code: # Start Rewrite Engine RewriteEngine On # Remove trailing slash RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^(.*)/$ $1 [R,L] # Remove need for ".html" RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [L] # Remove need for ".php" RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L] The issue then is that these specific rewrite rules affects aliases on the same domain so fx. example.com/phpmyadmin will cause redirect loops. To overcome this, the solution is to wrap the rewite rules in a Code: <Directory /var/www/clients/clientX/webX/web> and not the {docroot} snippet Code: <Directory /var/www/domain.com/web> like this Code: <Directory /var/www/clients/clientX/webX/web> # Start Rewrite Engine RewriteEngine On RewriteBase / # Remove trailing slash RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ $1 [R,L] # Remove need for ".html" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [L] # Remove need for ".php" RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.*)$ $1.php [L] </Directory> This also solves the problem where now, you cannot put for example "Options -Indexes" in Directives field, it does not have any effect. Currently on 18.04 (at least) directory indexes are shown as default - just go to /error/ on a webpage. It would be very nice if a snippet could be created for the real docroot path and not the symlinked one.
How could I create a new Snippet variable with the value of the real docroot path? In the vhost, the document root is /var/www/clients/clientX/webX/web, but the {docroot} snippet is /var/www/domain.com/web <Directory %{DOCUMENT_ROOT}> also gives /var/www/domain.com/web +FollowSymLinks in <Directory> doesn't work either.