styke
styke

Reputation: 2174

Can't remove index.php from codeigniter site URL?

I've read guides on its removal and they tell me to add this to a .htaccess in my htdocs root directory:

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

However my websites directory is like so: htdocs\mywebsite\

I've tried adding the htaccess file in both htdocs and mywebsite but without result. I've also tried modifying the last line to look like

RewriteRule ^(.*)$ mywebsite/index.php/$1 [L]

In both htdocs and mywebsite directory. But I have no idea what is correct .htaccess syntax or how it works, so I didn't really expect it to work.

I've also tried modifying the .htaccess file everywhere else in the codeigniter dir tree.

Upvotes: 2

Views: 3222

Answers (3)

styke
styke

Reputation: 2174

There needs to be a htaccess file in both the root and website directory. They need to both contain the same content except the file in root needs to have the path to the index updated to include your website dir.

Root dir:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ yourwebsite/index.php/$1 [QSA,L]

Web dir:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]

Upvotes: 1

Kenzo
Kenzo

Reputation: 3643

Make sure you have this in your virtual host entry:

    <Directory "/path...to directory">
        Order allow,deny
        Allow from all
        Allowoverride all
    </Directory>

    <IfModule mod_rewrite.c>
        RewriteEngine on
    </IfModule>

You don't need to modify any .htaccess files except in the root. And as mentioned above, make sure you have things set up right in the config.php file.

Upvotes: 0

dmgig
dmgig

Reputation: 4568

Have you seen this one? How to remove "index.php" in codeigniter's path

Did you change the index_path variable in the config file? That's application/config/config.php, line 29 in version 2.1.3

Upvotes: 3

Related Questions