It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In RegisterIt looks like you're new here. If you want to get involved, click one of these buttons!
Howdy, Stranger!
It looks like you've been lurking for a while.
If you register, we also will remember what you have read and notify you about new comments. You will also be able to participate in discussions.
So if you'd like to get involved, register for an account, it'll only take you a minute!
apt-get update
apt-get upgrade -y
Enabling mod_rewrite
First, we need to activate mod_rewrite (if it's not already activated):
a2enmod rewrite
This will activate the module or alert you that the module is already enabled. To put these changes into effect, restart Apache.
service apache2 restart
mod_rewrite is now fully enabled.
Setting Up .htaccess
An .htaccess file allows us to modify our rewrite rules without accessing server configuration files. For this reason, .htaccess is critical to your web application's security.
nano /etc/apache2/sites-available/000-default.conf
Note: If nano is not installed install it with:Inside that file, you will find a <VirtualHost *:80> block starting on the first line. Inside of that block, add the following:apt-get install nano
<Directory /var/www/html>To put these changes into effect, restart Apache.
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
service apache2 restartNow, create the .htaccess file in the web root (if you had installed WordPress, Joomla and so on, it's already created):
nano /var/www/html/.htaccessAdd this line at the top of the file to activate the rewrite engine.
RewriteEngine onNow you are able to start using URLs rewriting, which you will learn in next step.
nano /var/www/html/example.htmlCopy the following HTML code into the file, then save and close it.
<html>You can access this page at http://IP_of_your_server/example.html, but notice that if you try to access http://IP_of_your_server/example, you will see a 404 Not Found error. If you would users to access the page using simply /example instead, rewrite rules will allow this very functionality.
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
</body>
</html>
RewriteRule pattern substitution [flags]
nano /var/www/html/.htaccessAfter the first line, add the RewriteRule. It should look like this:
RewriteEngine OnThere is explanation of this rule:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ /$1 [L,R=301]