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

标签 php .htaccess codeigniter url-rewriting

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 上运行,您需要一个简单的 .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]

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/

相关文章:

java - PHP 运行 java jar 文件,参数作为 php 变量

php - 伪造文件扩展名

php - Laravel 验证双重嵌套

.htaccess - htaccess 如何删除尾随问号

.htaccess - Mod_rewrite 有效但路径已更改

apache - Plesk-Server 上的 Laravel - 只能通过调用/公共(public)访问

linux - Codeigniter 页面显示 404 页面未找到

PHP PDO SQLITE - 连接

php - 哪个更好地练习大方法或分离方法?

php - 谷歌搜索引擎中缺少网站片段