从 urlstring 中删除 Index.php 后网站无法正常工作?

发布于 2024-11-19 09:47:12 字数 763 浏览 0 评论 0原文

在我的旧网址中,它是 http://localhost/midas/index.php

我的网站正在使用 MVC 框架与代码点火器。

我在 Apache XAMPP 中激活了 mod_rewrite 并使用了以下 htaccess 代码:

 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /index.php/$1 [NC,R=301,L]

当我输入基本 url 时,一切正常,我的主页会加载:

基本 url = http://localhost/midas/

但是,当我单击导航菜单或链接时,我收到 404 未找到对象错误消息。

Apache 错误消息:

[2011 年 7 月 12 日星期二 13:48:55] [错误] [客户端 127.0.0.1] 文件不存在:C:/xampp/htdocs/midas/site,引荐来源:http://localhost/midas/

有什么我需要更改的地方吗?

In my old url it was http://localhost/midas/index.php

My site is using MVC framwork with CodeIgniter.

I activated mod_rewrite in Apache XAMPP and used the following htaccess code:

 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /index.php/$1 [NC,R=301,L]

When I enter my base url it is fine and my home page loads up:

base url = http://localhost/midas/

However when I click on my navigation menu or links I get a 404 object not found error message.

Apache Error Message:

[Tue Jul 12 13:48:55 2011] [error] [client 127.0.0.1] File does not exist: C:/xampp/htdocs/midas/site, referer: http://localhost/midas/

Is there something I need to change somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦上情书 2024-11-26 09:47:12

编辑 /application/config/config.php 并更改

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

$config['index_page'] = '';

此外,启用 mod_rewrite 后,您需要重新启动 Apache。

这是我与 CodeIgniter 一起使用的 .htaccess (经过修改,因此它应该适合您):

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

    #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
    RewriteCond $1 !^(index\.php|images|css|robots\.txt)
    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>

它应该位于您的根目录中(即 C:\xampp\htdocs\midas)。

Edit /application/config/config.php and change

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

to

$config['index_page'] = '';

Also, you will need to restart Apache after you've enabled mod_rewrite.

This is the .htaccess I'm using with CodeIgniter (modified so it should work for you):

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

    #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
    RewriteCond $1 !^(index\.php|images|css|robots\.txt)
    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>

It should be in your root directory (i.e. C:\xampp\htdocs\midas).

晨与橙与城 2024-11-26 09:47:12

您可能需要在 htaccess 中设置 RewriteBase

,请参阅:http://httpd.apache .org/docs/current/mod/mod_rewrite.html

我的猜测是

RewriteBase /midas

(就在 RewriteEngine 之后)

You might need to set a RewriteBase in your htaccess

see: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

My guess would be

RewriteBase /midas

(right after RewriteEngine)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文