2

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!

2 Answers 2

4

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 ?.

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

6 Comments

Thanks to you too, but problem isnt solved...my question was kinda messed up, so i wanna be clear that at this moment i can access site.com/index.php/acticle/3 only by typing it by myself and all links are working fine. >:o but i also can access site.com/article/3
Now, you make me get your question in different way. I guess what you mean is to access your site URI like: site.com/index.php/article
Sorry about confusion. But still, is it needed to be fixed or not? that links at website and links from google search are working great, but if i want i can go to site.com/index.php/article ? Sorry about me being so confusing too.
look, if your config is set to not display index.php in its URI and google search indexs is showing your pages as site.com/reviews/article so you're done. Although you'll be able to access directly your URI with index.php in it, but this is something you don't have to worry about, your site links will be not affected once your config it's working properly, If you're concerned users to access your site URI with by typing index.php in the URI you can make a 301 redirect but again is not really necessary.
ah, thank you very much, you made me calm down. that's exactly what i wanted to hear.
|
0

To remove index.php from codeigniter:

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

1 Comment

Thanks, but it doesnt change a thing. :(

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.