mod_rewrite (not .htaccess) conf not loading

Posted February 16, 2021 369 views


I’m having issues getting mod_rewrite to load my .conf. Can anyone please help me figure out how to debug this further to see where the issue is please?

rewrite is enabled on apache2. The Include related to loading .conf (/etc/apache2/conf.d/userdata/ssl/2_4/domain/ is uncommented. There is a file at that location. I did a rebuild + restart. Still nothing.

I’ve also added LogLevel alert rewrite:trace8 to the userdata conf and have a tail -f running on /var/log/error_log, reload the page in question and nothing appears in tail.

Any ideas what I might do next please?

Thank you

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi @appl3s,

I’m glad you were able to resolve the issue! Nevertheless, I’m posting this for anyone else that might find this question and need more information on the topic.

In order for Apache to understand rewrite rules, we first need to activate mod_rewrite. It’s already installed, but it’s disabled on a default Apache installation. Use the a2enmod command to enable the module:

sudo a2enmod rewrite

This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache.

sudo systemctl restart apache2

mod_rewrite should now be fully enabled and you should be able to edit your .htaccess file with your rewrite rules.

Having said that, DigitalOcean have a very good tutorial on that topic which can be checked here:


by Mateusz Papiernik
by Brian Hogan
Apache's mod_rewrite module lets you redirect URLs based on additional conditions, or rewrite URLs in a cleaner fashion, translating human-readable paths into code-friendly query string. In this tutorial, you'll enable `mod_rewrite` and use `.htaccess` files to create a basic URL redirection, and then explore a couple of advanced use cases.
  • Thank you, @KFSys.

    I have read these and many other docs. Unfortunately, for a variety of reasons, I am not keen on using .htaccess. It is extremely difficult to find any docs that detail setting up mod_rewrite using .conf files.

    There is a bit of info on cPanel’s site and a scant bit of detail in the form of comments in httpd.conf itself.

    Nonetheless, the only reason I figured this out was a complete fluke. One would think that a <VirtualHost ip:443>… section would pertain to loading https, and <VirtualHost ip:80> would pertain to loading http. For some reason, once I set up the modrewrite conf in my /etc/apache2/conf.d/userdata/std/24… directory, it worked with https. And yes, I can confirm that my Vhost:443 conf clearly says “Include …/ssl” not “Include …/std”.

    Would still love to know why this is?