Reassign index.php to CodeIgniter

I created a CodeIgniter application, and now I am trying to redirect URLs from index.php to URLs without it.

My current .htaccess:

RewriteEngine On RewriteBase / # Removes trailing slashes (prevents SEO duplicate content issues) RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)/$ $1 [L,R=301] # Enforce www # If you have subdomains, you can add them to # the list using the "|" (OR) regex operator RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC] RewriteRule ^(.*)$ http://www.plugb.com/$1 [L,R=301] # 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] 

The only problem is that the same page is available with and without index.php.

For example:

http://www.plugb.com/index.php/games/adventure-rpg

and

http://www.plugb.com/games/adventure-rpg

Is there a way to redirect index.php urls?

Thanks, Gabriel.

+4
php codeigniter .htaccess
May 18 '10 at 10:37 p.m.
source share
5 answers

Add this to the last rule:

 RewriteBase / RewriteCond %{HTTP_HOST} !="" RewriteRule ^index.php(/.*)?$ http://%{HTTP_HOST}$1 [R=301] 

or deny access:

 RewriteRule ^index.php(/.*)?$ - [R=404] 
+3
May 18, '10 at 22:53
source share

The CodeIgniter wiki documentation describes how to achieve this exact behavior.

This article explains how to remove "index.php" from your CI application URLs . However, it does NOT remove the need for Index.php, which is the CI front controller, i.e. Although Index.php will not appear in the URL, it should still be present at the top level of your site (above / system /).

0
May 18 '10 at 22:49
source share

You can try? RewriteRule ^ (. *) $ Index.php /? $ 1 [L]

Hope this works.

0
May 19 '10 at 15:17
source share

I came up with a workaround for this:

 $clean_url = str_replace('index.php','',current_url()); $current_url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; if($clean_url!==$current_url) { redirect($clean_url,'location',301); } 

This is not with .htaccess, but this in your controller may solve the problem. (At least he worked in PlugB )

0
May 21 '10 at 19:58
source share

You do not need to write code to redirect index.php URLS.

Go to application / config / config.php and make the following change

 $config['index_page'] = ""; 
0
Jan 16 '14 at 2:37
source share



All Articles