I used to host my websites with third-party hosting service and anchoring links was always easy. Then I decided to set my VPS. Everything is working well, besides the anchor links.
I found out that Apache, by default, doesn't allow me to use some symbols when accessing URLs, but also that is possible to use mod_rewrite to solve that. According to Apache's documentation, whenever I can choose between adding rewrite rules via <Directory>
instead of using .htaccess
files, I should do that. Also, to enable the rewrite engine, RewriteEngine On
and Options FollowSymLinks
must be enabled. Considering that I'm already using RewriteRules to force access through HTTPS (and this is working), I believe my system is ready to receive RewriteRules.
Therefore, I added the rewrite rule to <Directory>
but it's not reaching the expected result, which is instead of accessing mydomain.com/pageA/sectionB
, access the anchor mydomain.com/pageA#sectionB
. Maybe I'm adding the RewriteRule to the wrong place since I found in Apache's documentation this rule to do exactly what I expect. Am I doing something wrong? Follow my ".conf" file.
<VirtualHost *:80>
Servername mydomain.com
ServerAlias www.mydomain.com
RewriteEngine on
RewriteCond %(SERVER_NAME) =mydomain.com [OR]
RewriteCond %(SERVER_NAME) =www.mydomain.com
RewriteRule https://%{SERVER_NAME}%{REQUEST_URI} [END=301,L]
</VirtualHost>
<VirtualHost _default_:443>
ServerAdmin [email protected]
DocumentRoot /var/www/html/mydomain.com/
ServerName mydomain.com
ServerAlias www.mydomain.com
<Directory /var/www/html/mydomain.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
Allow from all
RewriteEngine on
RewriteRule "^/pageA/sectionB/" "/pageA#sectionB/" [NE,R]
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/my_certificate.cer
SSLCertificatekeyFile /etc/ssl/private/my_key.key
</VirtualHost>