RewriteEngine On
Redirect 301 /path/to/ressource.html https://renenyffenegger.ch/notes/development/Apache/Server/htaccess
Note: the redirected path seems to be required to be stated absolutely, even if the .htaccess files is placed in the same directory where the redirected ressource is stored.
Respond with 404 for directories and subdirectories
RewriteEngine On
ErrorDocument 404 https://url.xyz/path/to/404-document.html
Redirect 404 /path/of/directory/to/create/404/for
Don't serve .git directories
RedirectMatch 404 /\.git
Set PHP include path
Some sources on the Internet claim that it is possible to set the PHP include path with the following directive:
php_value include_path ".:/home/rene/php"
However, when I tried that, I got the error message Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration.
I was able to set the include path with a .user.ini file (to be placed in the same location as the .htaccess file) like so, though:
include_path=".:/home/rene/php"
Let Apache serve suspicious files with names like wget, too.
For security reasons, Apache does by default not really like to serve URIs that contain the word wget etc.
This behaviour can be turned off with the following snippet:
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
Redirect HTTP to HTTPS
Redirect a request to http://abc.yz/foo/bar.html to https://abc.yz/foo/bar.html.
In order to take effect for any url, the following .htaccess must pe put in the root directory.
The R=301 indicates a permanent redirect. Just an R would default to 302 (=Found). The L indicates the last rule (see also the .htaccess flags)
Since %{REQUEST_URI} apparently always starts with a slash, there is no need for a slash between the servername and the URI.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://renenyffenegger.ch%{REQUEST_URI} [R=301,L]
The following snippet didn't work in subdirectories. Apparently the regular expression only matches the last part of the URI: