To have a more linear structure in my blog I changed the subpath of posts
which are now under /post/
instead of /notes/
.
The problem is that external websites which link pages of my blog (backlinks)
do not know about this change, so to avoid dead URLs I needed to redirect
requests from /notes/\*.html
to /post/\*.html
.
These instructions work for the Apache HTTPD server
- login as root
-
enable the rewrite module
a2enmod rewrite
- in your virtual host enable the
FollowSymLinks
option -
the rewrite rule I use is like this
RewriteRule ^notes/(.*\.html)$ https://blog.franco.net.eu.org/post/$1 [R,L]
- notice the round brackets in
(.*\.html)
: those are required $1
correponds to the matched part in the source URL[R,L]
meanR
: apply external redirectL
: stop the rewriting rule after the current rule
- notice the round brackets in
Example #
Here is the full example of a virtual host
<VirtualHost *:443>
# [ ... ]
RewriteEngine on
ServerName blog.franco.net.eu.org
DocumentRoot "/var/www/blog.franco.net.eu.org"
<Directory "/var/www/blog.franco.net.eu.org">
Options -ExecCGI -Includes
Options FollowSymLinks
# No indexing.
Options -Indexes
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
RewriteRule ^notes/(.*\.html)$ https://blog.franco.net.eu.org/post/$1 [R,L]
</Directory>
# [ ... ]
</VirtualHost>