Skip to content

Instantly share code, notes, and snippets.

@vaibhav9392
Last active June 7, 2022 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vaibhav9392/027b7403d84f0bc99abf to your computer and use it in GitHub Desktop.
Save vaibhav9392/027b7403d84f0bc99abf to your computer and use it in GitHub Desktop.
1. Create a .htaccess file in your application root directory.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
# Disable server signature
ServerSignature Off
# DEFLATE by type - html, text, css, xml
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
# DEFLATE by type - javascript
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/x-js text/x-javascript
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
2. Change configurations.
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
3. Enable mod_rewrite module on server
sudo a2enmod rewrite
4. Restart apache
sudo service apache2 restart
5. To use mod_rewrite from within .htaccess files edit the default VirtualHost.
sudo nano /etc/apache2/sites-available/000-default.conf
6. Search for “DocumentRoot /var/www/html” and add the following lines directly below:
<Directory "/var/www/html">
AllowOverride All
</Directory>
7. Restart apache
sudo service apache2 restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment