Categories: Snippets

.htaccess file useful snippets

If you get 404 page not found error after installation.

In this case your server needs the RewriteBase option to be set. Open the .htaccess file in the main folder and add the following line to it:
RewriteBase /

The .htaccess should look like this:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
If you have installed the application into a sub folder you need to add the sub folder name after the /
The .htaccess file should look like this in this case:
RewriteEngine On
RewriteBase /your_sub_folder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

On Dreamhost you have to amend the .htaccess. If you get a “No Input File” error.

The htaccess file should look like this:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L]

If you get “no input file specified” error on goDaddy web host

you need to change the .htaccess as follows:
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?/$1 [L] 
</IfModule>
This error means that your servers PHP version is not 5.3 or higher. Contact your web host in order to update your PHP version to 5.3 or higher.

If you get a 500 Error after the installation try the following as .htaccess

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

If you get a 500 Error after the installation try the following as .htaccess

Another

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^([a-z0-9_-]+)\.html$ index.php/page/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|asset|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]

 

Share

Recent Posts

How to remove .html, .php, etc (extension) from URL?

To remove the .html extension from your urls, you can use the following code in…

5 years ago

Redirect non-www to www and HTTP to HTTPS using htaccess

Below snippet shows how to redirect a site from non-www to www (or viceversa) and…

5 years ago

Redirect non-www to www in .htaccess

Below snippet shows how to redirect a site from non-www to www [crayon-663155b0b318d349208847/] or [crayon-663155b0b3193011852485/]…

6 years ago

Common .htaccess file Redirects

Below shows common redirects using htaccess file. [crayon-663155b0b3325338564171/] The CI .htaccess shouldn't be in the…

6 years ago