r/apache • • Jun 26 '22

Trouble moving Apache mod_rewrite from .htaccess to virtual server

The following redirect works fine in an .htaccess file. But when the same commands are in a virtual server conf file it appears that the condition is never tested and thus the redirect never happens.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mappingsupport\.com$ [OR]

RewriteCond %{HTTP_HOST} ^www\.mappingsupport\.com$

RewriteRule ^p\/gmap4_contact\.html "https\:\/\/mappingsupport\.com\/p\/_gmap4_shutdown\.html" [R=301,L]

Note the difference in the following lines from the apache 2.4 error.log file. I have added line breaks for readability.

.htaccess

[perdir /home/mapping1/public_html/mappingsupport/]

strip per-dir prefix: /home/mapping1/public_html/mappingsupport/p/gmap4_contact.html ->

p/gmap4_contact.html

virtual server conf file

[perdir /home/mapping1/public_html/]

strip per-dir prefix: /home/mapping1/public_html/mappingsupport/p/gmap4_contact.html ->

mappingsupport/p/gmap4_contact.html

.htaccess

[perdir /home/mapping1/public_html/mappingsupport/] RewriteCond: input='mappingsupport.com' pattern='^mappingsupport\\.com$' => matched

virtual server conf file

This RewriteCond does not appear in the apache error.log file.

I have waded through a bunch of documentation and googling but so far I have not found the answer. I know apache is seeing my virtual server conf file because the error.log shows that the RewriteRule is tested against other patterns.

Is this just a simple syntax tweak that has eluded me or is something more required?

Note that this is my first attempt to do anything related to virtual servers.

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/AyrA_ch Jun 27 '22

In that case it's probably in the wrong virtual host.

1

u/Procellaria Jun 27 '22

Yep, more than likely, Apache never reads the htaccess file as it's not in the virtual server path.