skip to Main Content

I have seen other articles on the same issue. But none of the answers have solved my problem.

I am not using xampp or wamp but have setup php mysql apache seperately. Also I am using my own local domain for instance mytestsite.com.

My .htaccess file looks like this:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /TestCI/

    # Canonicalize Codeigniter URLs

    # If your default controller is something other than
    # "welcome" you should probably change this
    RewriteRule ^(HomeController(/index)?|index(.php|html?)?)/?$ / [R=301,L]
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Removes trailing slashes (prevents SEO duplicate content issues)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [R=301,L]

    # Enforce www
    # If you have subdomains, you can add them to 
    # the list using the "|" (OR) regex operator
    RewriteCond %{HTTP_HOST} !^(www|TestCI) [NC]
    RewriteRule ^(.*)$ http://www.mytestsite.com/$1 [R=301,L]

    # Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>

    # Without mod_rewrite, route 404's to the front controller
    ErrorDocument 404 /index.php

</IfModule>

I have also made following changes in config.php

$config['base_url'] = 'http://mytestsite.com/TestCI/';    
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO'; //AUTO

I have also made following changes in apache2.conf

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

But when i try to access

http://mytestsite.com/TestCI/HomeController/

its showing 404 error but works correctly when using

http://mytestsite.com/TestCI/index.php/HomeController/

I have looked into several similar questions that have been reported solved, but none of the answers have worked for me. Is there anything else that should be done to remove index.php from the url. Kindly respond back. Help highly appreciated.

4

Answers


  1. Chosen as BEST ANSWER

    Thankyou for helping me... Problem is solved.

    I made the following changes in my apache2.conf file

    <Directory /Absolute path to .htaccess folder
    
            AllowOverride All
            Require all granted
    </Directory>
    

    Also I removed the RewriteBase parameter in .htaccess file which is where the actual pbm was.

    My current .htaccess file looks like

    <IfModule mod_rewrite.c> 
        RewriteEngine On
    
    
        #Removes access to the system folder by users.
        #Additionally this will allow you to create a System.php controller,
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    
    </IfModule>
    
    <IfModule !mod_rewrite.c>
        ErrorDocument 404 /index.php 
    </IfModule>
    

    I have also made changes in config.php where i changed $config['base_url'] to codeigniter root path


  2. Replace the following line of code in your .htaccess file

    RewriteEngine On
    RewriteBase /project/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
    
    Login or Signup to reply.
  3. Just put this code in your .htaccess :

    RewriteEngine on
    RewriteCond $1 !^(index.php|resources|robots.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    
    Login or Signup to reply.
  4. It may be the htaccess isn’t being used.

    Put a sytax error in the file. (Append something like hdtbf to the file)

    If that doesn’t give a 500 error you need to turn allow override all
    In your main Apache config

    http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search