Aktivera .htaccess i Apache

htaccessOm du använder web-servern Apache 2 har du möjlighet att göra omfattande konfigurationer så den till slut gör som du vill.
Om du inte har tillgång till konfigurationsfilerna så finns det ett nöd-system som eventuellt är aktiverat: htaccess

Ifall du har tillgång till web-serverns konfiguration och vill aktivera det här nödsystemet för dina användare på Ubuntu 16.10 så kan du göra så här:

Aktivera rewrite-modulen i Apache:

sudo a2enmod rewrite

Starta om Apache:

sudo service apache2 restart

Öppna konfigurationsfilen för din webbsite

sudo nano /etc/apache2/sites-available/000-default.conf

Lägg till eller modifiera den här sektionen

<Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Den viktiga delen är ”AllowOverride All”. Starta om Apache.
Du kan nu skapa en .htaccess fil i /var/www och även i underkataloger till den katalogen. Glöm inte att filens namn ska börja med en punkt.

Här är ett exempel på en htaccess-fil som används i projektet ”Infohub”.

php_flag opcache.enable Off
RewriteEngine on
DirectoryIndex index.php
RewriteRule ^folder/test/include/testmenu($|/) - [L]
RewriteRule ^folder/ - [R=404,L,NC]
RewriteRule ^.idea/ - [R=404,L,NC]
RewriteRule ^.hg/ - [R=404,L,NC]
RewriteRule .hgignore - [R=404,L,NC]

# You can turn off features here
# RewriteRule test.php - [R=404,L,NC]
# RewriteRule testmenu.php - [R=404,L,NC]
# RewriteRule phpinfo.php - [R=404,L,NC]
# RewriteRule callback.php - [R=404,L,NC]

## Every existing file, folder and link should be accessible
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

### every other url go to callback.php
RewriteRule  ^(.*)$ callback.php?param=$1 [QSA,L]

Källor ”Ask Ubuntu

CharZam