如何在Apache Server中设置CodeIgniter .htaccess文件

我在Windows 7操作系统上安装了Apache 2.2,Php 5.4.5和Mysql 5.5.27。 我的localhost位置是G:/ local_server。 我已下载CodeIgniter_2.1.3并解压缩到local_server并重命名CodeIgniter。 我在CodeIgniter文件夹上创建一个.htaccess文件并通过以下代码:</ p>

 &lt; IfModule mod_rewrite.c&gt; 
#打开URL重写
RewriteEngine On

#如果您的网站从文件夹开始,例如localhost / my_project,那么
#您必须将其更改为:RewriteBase / my_project /
#如果您的网站从根目录开始,例如 example.local / then
#let it it

RewriteBase / CodeIgniter /

#保护应用程序和系统文件在index.php缺失时被查看
RewriteCond $ 1 ^(application | system | private | logs )

#重写为index.php / access_denied / URL
RewriteRule ^(。*)$ index.php / access_denied / $ 1 [PT,L]

#允许直接显示这些目录和文件:

RewriteCond $ 1 ^(index \ .php | robots \ .txt | opensearch \ .xml | favicon \ .ico | assets | forums)

#No rewriting
RewriteRule ^(。*)$ - [PT,L]

#重写为index.php / URL
RewriteRule ^(。*)$ index.php / $ 1 [PT,L]
&lt; / IfModule&gt;
</ code> </ pre>

然后我从application / config / config.php更改了以下行</ p>

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

$ config ['uri_protocol'] ='自动'; to $ config ['uri_protocol'] ='REQUEST_URI';
</ code> </ pre>

我还从Apache httpd.conf中删除#行:</ p>
\ n

  LoadModule rewrite_module modules / mod_rewrite.so 
</ code> </ pre>

但我仍然无法隐藏CodeIgniter中的index.php文件。 :( </ p>

帮助赞赏。:)</ p>
</ div>

展开原文

原文

I have installed Apache 2.2, Php 5.4.5 and Mysql 5.5.27 on Windows 7 Operating System. My localhost location is G:/local_server. I have downloaded CodeIgniter_2.1.3 and extract to local_server and rename CodeIgniter. I crate a .htaccess file on CodeIgniter folder and Past this following code:

<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On

# If your website begins from a folder e.g localhost/my_project then 
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase / CodeIgniter/

# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)

# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]

# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)

# No rewriting
RewriteRule ^(.*)$ - [PT,L]

# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>

Then I changed following line from application/config/config.php

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

$config['uri_protocol'] = 'AUTO'; to $config['uri_protocol'] = 'REQUEST_URI';

I have also delete # from Apache httpd.conf following line:

LoadModule rewrite_module modules/mod_rewrite.so

But still I can’t hide index.php file from CodeIgniter. :(

Help appreciated. :)

duanmengmiezen8855
duanmengmiezen8855 你有运气吗?
7 年多之前 回复
dpbfb7119
dpbfb7119 该文件是.htaccess,而不是.hitaccess。这可能是您问题的一部分。
7 年多之前 回复
douhezhang8932
douhezhang8932 我在下面的回答将解决您的问题,但为了将来参考,您尝试在文件中加载“mod_rewrite.c”但Apache正在加载“mod_rewrite.so”。两个不同的模块。
7 年多之前 回复

1个回答



这是我很好的'可靠的Codeigniter .htaccess文件:</ p>

  RewriteEngine On \  n RewriteBase / 
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteCond $ 1!^(templates | plugins)
RewriteRule ^(。*)$ index.php / $ 1 [L ]
</ code> </ pre>

然后将您的基础重写为您需要的任何内容,添加您需要访问的目录(我有模板和插件),您应该好好去。 </ p>

当然,还要确保Apache启用了mod_rewrite,否则你将无法到达任何地方!</ p>
</ div>

展开原文

原文

Here's my good 'ol trusty Codeigniter .htaccess file:

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

Then rewrite your base to whatever you need, add the directories you need to access (I have templates and plugins there) and you should be good to go.

Of course, also make sure Apache has mod_rewrite enabled otherwise you won't get anywhere!

duanliusong6395
duanliusong6395 对于那些贬低我的人,你能解释一下原因吗?
6 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐