Codeigniter Url Rewriting .Htaccess Is Not Working on Centos

Codeigniter URL rewriting .htaccess is not working on CentOS

You need to also specify the locations that can use it. For example, in /etc/httpd/conf/httpd.conf you should see something like:

<Directory "/var/www/html">

...lots of text...

</Directory>

Make sure is has:

<Directory "/var/www/html">

AllowOverride All

</Directory>

CodeIgniter htaccess and URL rewrite issues

There are 3 steps to remove index.php.

  1. Make below changes in application/config.php file

    $config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
    $config['index_page'] = '';
    $config['uri_protocol'] = 'AUTO';
  2. Make .htaccess file in your root directory using below code

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  3. Enable the rewrite engine (if not already enabled)

    i. First, initiate it with the following command:

    a2enmod rewrite

    ii. Edit the file /etc/apache2/sites-enabled/000-default

    Change all AllowOverride None to AllowOverride All.

    Note: In latest version you need to change in /etc/apache2/apache2.conf file

    iii. Restart your server with the following command:

    sudo /etc/init.d/apache2 restart

Codeigniter mod rewrite in CentOS

On my CentOS I only have this:

RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt|resources)
RewriteRule ^(.*)$ index.php/$1 [L]

But my site resides in /var/www/html. I am by no means an expert on Apache, but perhaps you need to set the

RewriteBase /home/virtual/site777/somefolder/var/www/html/

As well

CodeIgniter .htaccess index.php rewrite not working on user directory

Well, I found a solution in codeigniter forums, first I need to add RewriteBase line as follows:

RewriteBase /~userdir/myproject/

Then, remove the slash before index.php on last line.

RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

Someone said that

RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)

is redundant, the following two lines of code cover it,

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

and all other real files/directories. They basically say "if the request is not for a REAL file, and the request is not for a REAL directory, pass the request to index.php. Presumably everything from the above line is a real file or directory, so it's not needed at all.

So, my final .htaccess is like this:

RewriteEngine on
RewriteBase /~userdir/myproject/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]

It works well locally with http://localhost/~userdir/myproject also on production with http://example.com/~userdir/myproject

.htaccess is not working apache

.htaccess is turned off by default

Directives in .htaccess files can override the settings in the main Apache configuration file, but by default that feature is turned off. To use htaccess, it needs to be turned on in the main Apache configuration file.

If you are managing your own server, open httpd.conf and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All



Related Topics



Leave a reply



Submit