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

时间:2014-07-03 16:20:44

标签: php .htaccess codeigniter rewrite

stackoverflow社区。 我删除了site.com/index.php dublicate,我确实添加了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

提前致谢!

2 个答案:

答案 0 :(得分:4)

要在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.php中

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

这将产生:

www.site.com/reviews/acticle/3 - &gt; site.com/reviews/acticle/3 www.site.com/index.php/reviews/acticle/3 - &gt; site.com/reviews/acticle/3

并且还要摆脱?

答案 1 :(得分:0)

从codeigniter中删除index.php:

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