Enable mod_rewrite on openSUSE Linux
Description of the problem: By default, openSUSE doesn’t enable the mod_rewrite rewrite module. It’s however installed, but not enabled.
Follow these steps to install it:
Step 1: Enable mod_rewrite on SuSE linux
-
a.: Edit the file /etc/sysconfig/apache2 (as root!): and search for APACHE_MODULES, you should find a line like this:
APACHE_MODULES="suexec access actions alias auth auth_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif userdir ssl php4" -
b.: Add rewrite to the content in the list between the “ It should now look like:
APACHE_MODULES="suexec access actions alias auth auth_dbm autoindex cgi dir env expires include log_config mime negotiation setenvif userdir ssl php4 rewrite" -
c.: Save the changes and quit
run /etc/init.d/apache2 restart to restart the Apache server
Now, the mod_rewrite is enabled and integrated.
Step 2: Check if mod_rewrite is installed and integrated in Apache
You can check this e.g. with the following php file. Create a file by the name of testphp.php in your document root of your webserver (default on SuSE: /srv/www/htdocs) and copy the following content into this file:
<?php phpinfo(); ?>
When you view this file with your browser by entering localhost/testphp.php in the address window, search for rewrite – you should find one entry as showed in the picture below:
If not – check if you did all steps a to c.
Step 3: Test .htaccess rewrite rule on SuSE linux Apache
The next step is to create an initial .htaccess rewrite rule to test if it’s working now. Create a file .htaccess in your document root (default on SuSE: /srv/www/htdocs) with the following content:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
</IfModule>
This is a simple rule that redirects all urls with the format user/something to the script /user.php with the something as parameter user. The IfModule prevents Apache errors when mod_rewrite should disappear.
Step 4: Sometimes (especially the combination Drupal 8 and openSuse 15.x/PHP 7) this doesn't work so let's Enable custom Apache .htaccess in an other way.
If the above listed steps 1 to 3 don’t work – there could be another pitfall of the default SuSE Apache installation: you’re not allowed to create custom .htaccess files! So – lets enable them!
-
Edit the file /etc/apache2/default-server.conf with your prefered editor and the proper rights.
- Search for Options None – it should be below the line <Directory "/srv/www/htdocs">
- Change this into Options Indexes FollowSymLinks MultiViews
- Add a line: Require all granted
-
Search for AllowOverride – it should be below the line <Directory "/srv/www/htdocs">
-
Change AllowOverride None to AllowOverride All – this will allow custom .htaccess rewrite rules.
- The changed text should now be:
<Directory /srv/www/htdocs>
Options Indexes FollowSymLinks MultiViews
Require all granted
AllowOverride All
</Directory> -
Save your changes and exit the editor.
-
run 'sudo /etc/init.d/apache2 restart' or 'sudo service restart' to restart the Apache server
That’s all, now you can test the .htaccess rewrite rule again and it will work.
Step 5: '403 access denied' error after enabling mod_rewrite.
Recently I encountered another problem when adding a custom subfolder to a standard Drupal 8 installation:
If however for some reason you still get the '403 access denied' error when trying to access that directory then add the following lines to your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
# stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/<name of your subfolder>/"
RewriteRule (.*) $1 [L]
</IfModule>
This worked for me on an installation of Drupal 8