【问题标题】:having headache wtih codeigniter mod_rewrite ~!对 codeigniter mod_rewrite 感到头疼~!
【发布时间】:2013-05-26 07:57:39
【问题描述】:

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

的内容

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

之后,我继续学习 youtube 上关于 mod_write 的教程。我在 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页面。

我只是不断得到..

由于我使用的是 wamp,所以当我转到本地主机时,有一个部分说我的项目是 ci_intro...我点击它,上面的图片就出来了。 我把鼠标放在上面看看当鼠标悬停和链接显示时链接显示的是什么

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

有人知道这里发生了什么吗?

【问题讨论】:

    标签: .htaccess codeigniter mod-rewrite


    【解决方案1】:

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

    这是因为您使用“www.domain.tld”而不是“localhost”来访问您的网站。

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

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

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

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

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

    【讨论】:

    • 当我访问 C:\Windows\system32\drivers\etc\hosts 这是我看到的 127.0.0.1 localhost 127.0.0.1 mpa.one.microsoft.com 127.0.0.1 localhost 127.0.0.1 localhost所有其他人都被注释掉了
    • @user1850712,添加行:127.0.0.1 www.domain.tld,保存文件,然后关闭浏览器(所有选项卡和窗口)。这将导致您的浏览器将您的假域名解析为本地系统 IP(始终为 127.0.0.1)。
    • 刚刚尝试过,但它只会让我回到我的本地主机页面并在 URL 中显示 www.domain.tld 而不是本地主机。
    • 我在 config/routes.php 中做了一些事情,因为有一个论坛在谈论它。我的firefox仍然有我在这里谈论的同样的问题,但是当我使用chrome时,在我配置了routes.php之后,一切都很好。重新安装 Firefox 会对此有所帮助吗?
    • 哦...嗯...在本地主机中确定我单击了 ci_intro 然后它以 www.domain.tld 作为 URL 返回到本地主机...然后再次单击 ci_intro ...链接有效但显示www.domain.tld/ci_intro/home ....似乎它可以工作...在某种程度上....至少这可以让我继续教程...但只是想知道...是否有可能的方法让它再次显示本地主机? (只是好奇现在不是什么大问题,因为它现在有点用)
    猜你喜欢
    • 1970-01-01
    • 2017-10-28
    • 2012-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多