Tuesday, December 27, 2016

Apache URL rewrite in Ubuntu

1. Enable url rewriting using the command,
a2enmod rewrite
2. Open the file /etc/apache2/apache2.conf and uncomment the line,
AccessFileName .htaccess
3. Update the security model
<Directory /var/www>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>
4. Create file .htaccess in web site's root folder

5. Add the below line to the beginning of the .htaccess file
RewriteEngine on
6. Add the rewrite rule and conditions below it,
e.g. RewriteRule ^api\/v([0-9]+)\/((([a-zA-Z]+)|(([a-zA-Z]+)\/([a-zA-Z]+)))+)\/?$ index.php?v=$1&api=$2 [L]

No comments:

Post a Comment