Apache2 Virtual Hosts and mod_rewrite Configuration

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Keith Smith via PLUG-discuss
Date:  
To: Main PLUG discussion list
CC: techlists
Subject: Apache2 Virtual Hosts and mod_rewrite Configuration
Hi,

I am looking at some documentation that seems to be contradictory.

The default root for Apache2 is /var/www/html. (on Ubuntu 24.04lts)

The article I am looking at shows that a new virtual host should have a
path /var/www/[domain]/public_html.

So far so good.

ChatGPT says to add the following code to the default virtual host
configuration file as part of the configuration of mod_rewrite:

<Directory /var/www/html>
     RewriteEngine On
     RewriteRule ^oldpage.html$ newpage.html [R=301,L]
</Directory>


I'm thinking to make the mod_rewrite apply to all virtual hosts the path
needs to be /var/www/ like this:

<Directory /var/www/>
     RewriteEngine On
     RewriteRule ^oldpage.html$ newpage.html [R=301,L]
</Directory>


Another article shows:

     <Directory /var/www/html>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
     </Directory>


This seems to imply each virtual host will need to be configured
individually for mod_rewrite like this:

     <Directory /var/www/[domain]/public_html/>
         Options Indexes FollowSymLinks
         AllowOverride All
         Require all granted
     </Directory>


And the mod_rewrite configuration also requires a .htaccess file.

Any thoughts are much appreciated.

Keith
---------------------------------------------------
PLUG-discuss mailing list:
To subscribe, unsubscribe, or to change your mail settings:
https://lists.phxlinux.org/mailman/listinfo/plug-discuss