stackoverflow 社区。 我删除了重复的 site.com/index.php 并添加了 www,所以它看起来是 www.site.com 并且工作得很好。经过所有这些操作后,我遇到了一个问题 - 如果我从显示非 www 版本的 google 搜索转到我的网站,我会被重定向到 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
提前致谢!
最佳答案
要让 Codeigniter 在 apache 上运行,您需要一个简单的 .htaccess
和 config.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]
application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
这将产生:
www.site.com/reviews/acticle/3
--> site.com/reviews/acticle/3
www.site.com/index.php/reviews/acticle/3
--> site.com/reviews/acticle/3
并且还要去掉?
。
关于php - 删除index.php并在htaccess Codeigniter中添加www,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24558858/