Skip to main content

Sadržaj

apache 2

remove index.php

mod_rewrite

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule (.*) /index.php/$1 [L]

remove .php ili .html RewriteEngine On RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^([^.]+)$ $1.php [NC,L] RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^.]+)$ $1.html [NC,L]

sudo a2enmod rewrite

and

sudo service apache2 restart

Modify the corresponding section of your apache2.conf file to the following.

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule (.*) $1.php [L] RewriteCond %{THE_REQUEST} /([^.]+).php [NC] RewriteRule ^ /%1 [NC,L,R] </Directory> If using .htaccess to re-write ensure that the apache2.conf at least has these options enabled.

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted RewriteEngine On </Directory> Finally on some Apache install you may need to also set AllowOveride All in a .conf file in /etc/apache2/sites-available or /etc/apache2/sites-enabled. Rewriting from apache2.conf file as opposed to .htaccess is rumored to be faster.

Checks if the rewrite mod is on.

RewriteEngine On
# Force everything through the index.php file
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]