删除index.php并在htaccess Codeigniter中添加www


Remove index.php and add www in htaccess Codeigniter

stackoverflow社区。我删除了site.com/index.php复制,我确实添加了www,所以它看起来www.site.com,工作得很好。所有这些操作后,我面临一个问题-如果我去我的网站从谷歌搜索显示非www版本,我重定向到www版本,但我得到了/?/在ulr的中间,比如site.com/?/reviews/acticle/3…它工作了,打开了。然而,我设法摆脱了/?/现在一切都很好,但我的问题是:如果我去site.com/index.php,它会重定向到主页如果我直接输入f.e. site.com/index.php/reviews/article/3,它仍然可以工作。所以,这是不是一个坏信号,它仍然有效,没有重定向我?除了通过谷歌搜索之外,我无法通过其他方式访问它,只能自己输入。这是我的htaccess文件,我希望它看起来不是太乱:

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

提前感谢!

要在apache上运行Codeigniter,您需要一个简单的.htaccessconfig.php设置。

。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]

/config/config . php应用

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

这将产生:

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

和去掉?

从codeigniter中删除index.php:

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