0

我正在使用 codeigniter,当我设置网站时,我在 .htaccess 文件中添加了必要的代码,以从我的网址中删除 index.php (默认)。我只是碰巧从我网站的备份文件中替换了我的 public_html 文件夹。因为我这样做了,除非在域名和 URL 的其余部分之间的 URL 中插入 index.php,否则我无法让主页上的任何链接工作,如http://www.obsia.com/index.php /contact/而不是http://www.obsia.com/contact/并且它有效。所以,在我的应用程序文件夹中的配置文件中,我改变了

$config['index_page'] = "";  

$config['index_page'] = "index.php";

并且所有链接现在似乎都可以使用。但是如何从 URL 中删除 index.php。

这是我的 .htaccess 代码的样子:

RewriteEngine on
RewriteBase / 
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]

谁能指出我正确的方向。将不胜感激。

问候, G

4

2 回答 2

3

你想做的事情可以这样完成:

RewriteEngine on
RewriteBase / 
# Static content. Rewrite to - (don't change) and mark as last rule.
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L]

# Do the rewrite.
RewriteRule ^(.*)$ /index.php?/$1 [L]

但是,这样做的稍微好一点的方法是:

RewriteEngine on
RewriteBase / 
# Only do the rewrite under the condition that the requested URL isn't a (real) file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]
于 2011-03-22T23:10:00.133 回答
2

有这么多的 ht 访问文件...在我的情况下,我编辑了错误的文件...您应该编辑项目内部的文件..例如,我在代码点火器上工作,项目名称是 test ,所以在 test文件夹我有一个 htaccess 文件,在我的应用程序文件夹内,即 test/application 还有另一个 htaccess 文件。我正在编辑应用程序文件夹内的访问文件,但我必须编辑测试文件夹中的文件,而不是 test/application/.htaccess ....希望 sum 1 觉得这很有用..因为我花了半天时间才弄清楚:(

干杯 ksp

于 2012-11-08T09:53:49.793 回答