How to enable mod_rewrite for default vhost?

NethServer Version: 7.6

Hi,

It looks like a very simple question but without a simple answer : how do I enable mod_rewrite and correct .htaccess file handling for the default vhost ?

I want to host a wordpress site directly on www.domain.tld and domain.tld. after migration I see that all the links to pages are 404.

As far as I can see with php_info(), mod_rewrite is not enabled but I don’t really understand where to enable it.

Anybody can help ?

Txs

Hi pagaille.

Create the file to be read/add to httpd.conf
VHOST_DIRECTORY_NAME is the name given to your vhost

cat > /etc/httpd/conf.d/z_WordPress.conf <<'EOT'
# ************************************** 
# To enable Apache to read the .htaccess in WordPress
<Directory "var/lib/nethserver/vhost/VHOST_DIRECTORY_NAME">
    Options Indexes FollowSymLinks
    #
    AllowOverride All
    #
    Require all granted
</Directory>

EOT

Restart Apache

systemctl restart httpd

Create .htacces in the root of your vhost (VHOST_DIRECTORY_NAME)

# ************************************** 
# Pour les permaliens
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /affaires/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /affaires/index.php [L]
</IfModule>

# **************************************
# DIRECTIVES POUR APACHE
#
# Permet au serveur de suivre les liens symboliques dans les répertoires concernés.
Options +FollowSymLinks

# Empêche d'afficher le contenu des répertoires s'ils ne contiennent aucun DirectoryIndex
# c'est-à-dire index.html, index.php etc...
Options -Indexes

If you use WordFence then after installing it:

# **************************************
# Wordfence WAF
<IfModule mod_php5.c>
        php_value auto_prepend_file 
'/var/lib/nethserver/vhostl/VHOST_DIRECTORY_NAME/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
        Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
</IfModule>
</Files>

# END Wordfence WAF

Ajust right

chmod 444 .htaccess

Ajust owner/group

chown apache:apache .htaccess

For more details see: https://www.micronator.org/affaires/produit/nethserver-101-cahier-06nethserver-wordpress/

For Wordfence see: https://www.micronator.org/affaires/produit/nethserver-101-cahier-07wordpress-wordfence/

Those two documents are RC-001

Michel-André

Merci @michelandre !

But I think we should use the template system don’t we ?

Moreover, I’m using the default vhost, the one in /var/www/html

Hi pagaille,

There is no template for httpd.conf in 7.6.1810

Change directly in httpd.conf under <Directory "/var/www/html">

##### AllowOverride None
AllowOverride All

Michel-André

1 Like

Oh I didn’t know. And indeed I just found out that the AllowOverride wasn’t correctly set in that httpd.conf file.

SOLVED ! THANKS !

Hi again pagaille,

I saw that you downloaded the WordPress PDF.

There is an error in it:
When you specify a file to be included in the backup data, there is no “/” at the end.
The “/” is for specifying a directory to be included in the backup data.
If there is one “/” for a file, it will be included in /etc/backup-data.d/custom.include but the backup will not backup it because it will see that it is a file and not a directory.

Especially for: /etc/profile.d/activer-php72.sh which is a file, not a directory.

Michel-André