Alexander Yakovluk
Alexander Yakovluk

Reputation: 79

Remove index.php and add www in htaccess Codeigniter

stackoverflow community. I removed site.com/index.php dublicate and i did add www, so it looks www.site.com and works pretty fine. After all this manipulations i faced a problem - if i go to my website from google search which is showing non-www version, i got redirected to www version, but i got /?/ in the middle of ulr, like site.com/?/reviews/acticle/3 ...thou it worked and opened article. However i managed somehow to get rid of /?/ and all working fine right now, but my question is: if i go site.com/index.php it redirects me to the home page if i go direct by typing it in f.e. site.com/index.php/reviews/article/3 it still works. So, is it bad sign that it still works and doesnt redirect me? I cant access it any other way, f.e. from google search, except typing it by myself. Here is my htaccess file, i hope it isnt look like a too big mess:

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^site.info$
RewriteRule (.*) http://www.site.info/$1 [R=301,L] 

RewriteCond $1 !^(index.php|images|upload|robots.txt|css)
RewriteCond %{REQUEST_URI} !.(css¦js¦jpg¦gif)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA] 

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.site.info/$1 [R=301,L]
AddDefaultCharset UTF-8

Thanks in advance!

Upvotes: 2

Views: 1554

Answers (2)

Adriano Rosa
Adriano Rosa

Reputation: 8761

To get Codeigniter running on apache you need a simple .htaccess and config.php setup.

.htaccess

RewriteEngine On

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Remove WWW from the url
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
#RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Optional to redirect trailing slashes
#RewriteRule ^(.*)/$ /$1 [L,R=301]

# Point all URI to codeigniter bootstrap except direct access to file or dir
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

application/config/config.php

$config['base_url']  = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

This will produce:

www.site.com/reviews/acticle/3 --> site.com/reviews/acticle/3 www.site.com/index.php/reviews/acticle/3 --> site.com/reviews/acticle/3

and also get rid of ?.

Upvotes: 4

RNK
RNK

Reputation: 5792

To remove index.php from codeigniter:

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

Upvotes: 0

Related Questions