与codeigniter mod_rewrite头痛〜!

时间:2013-05-26 07:57:39

标签: .htaccess codeigniter mod-rewrite

我读了很多关于codeigniter的mod_rewrite,很多人都在谈论创建一个.htaccess文件,并在文件中用类似

的内容

我是codeigniter的初学者,所以我正在学习youtube教程。 起初我只安装了apache 2.2来运行我的php并在使用codeigniter和mod_rewrite之后我意识到它更容易安装wamp所以我卸载了apache,mysql然后安装了wamp,它拥有一切。

之后我继续关于mod_write的关于youtube的教程。我在wamp中激活了模块。

在ci_intro中创建了这个.htaccess文件,这是根文件夹

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ci_intro/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

我去了config / config.php并更改了

$config['index_page'] = '';
事情没有用。我得到了404error,然后我在

中尝试了一些事情
RewriteBase /ci_intro/

甚至还删除了整个项目,因为我在尝试mod_write之前就提供了支持。即使我检索了备份。我仍然没有得到error404页面。

我只是继续......

ci error

由于我正在使用wamp,当我去我的localhost时,有一节说我的项目是ci_intro ...我点击它上面的图像出来了。 我把鼠标放在检查鼠标悬停和链接显示

时显示的链接是什么

[CODE] http://localhost/ci_intro[CODE]

谁知道这里发生了什么?

1 个答案:

答案 0 :(得分:0)

您获得的浏览器页面是使用虚假或未注册域名的结果...浏览器无法将其解析为IP地址,因此通过将您的请求重新解释为搜索来“帮助”您术语

这种情况正在发生,因为您使用“www.domain.tld”而不是“localhost”来访问您的网站。

我不确定您使用的WAMP分布(有很多“WAMP”),但您的选择是:

A)编辑Windows主机文件(C:\ Windows \ system32 \ drivers \ etc \ hosts)以在本地解析“www.domain.tld”到本地IP地址127.0.0.1(并确保您的VirtualHost或服务器)将该域名作为ServerName指令的一部分。)

B)改为使用“localhost”...... http://localhost/

C)使用WAMP自动为您设置网站VirtualHosts,并具有像Wamp-Developer Pro那样的LocalDNS功能 - 所以上述都不重要。

现在一旦你通过了,可能会有其他一些问题......我猜测.htaccess文件应该在DocumentRoot文件夹中。