0

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.

2
  • 1
    Try my code may be it help... Commented Oct 3, 2015 at 6:04
  • still showing Not found error The requested URL /var/www/mytestsite.com/public_html/TestCI/index.php was not found on this server. Commented Oct 3, 2015 at 15:23

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

I have already made changes in allow override all. Its still same
did you restart the server ?
And it did give an internal server error when I made syntax mistake in .htaccess file. I still cant find what the issue is
Yes restarted the server several times. After making all those changes. but it just dont work without index.php in the url.
still showing Not found error The requested URL /var/www/mytestsite.com/public_html/TestCI/index.php was not found on this server.
1

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]

4 Comments

Have made the changes, but still no success
I have changed my answer, check once now
Still same. .htaccess file now looks like <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /TestCI/ #Removes access to the system folder by users. #Additionally this will allow you to create a System.php controller, RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?/$1 [L] </IfModule> <IfModule !mod_rewrite.c> ErrorDocument 404 /index.php </IfModule>
1

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]

2 Comments

Can u please explain RewriteCond $1 !^(index.php|resources|robots.txt)
still showing Not found error The requested URL /var/www/mytestsite.com/public_html/TestCI/index.php was not found on this server.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.