【问题标题】:Referencing a page not working [duplicate]引用页面不起作用[重复]
【发布时间】:2015-04-14 07:51:29
【问题描述】:

我正在使用 codeigniter 3.0 和 xampp。当我尝试使用 codeigniter 引用 xampp 中的页面时,它会转到 xampp 索引页面。

这是我的 .htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and     leading
#  slashes.
# If your page resides at
#  http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
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>

【问题讨论】:

    标签: php .htaccess codeigniter mod-rewrite codeigniter-3


    【解决方案1】:

    您可以尝试http://localhost/project/index.php/route-name 但如果您尝试在没有 index.php 的情况下执行此操作,请尝试下面的示例。

    免责声明:我不知道您正在运行什么版本的系统/服务器,因此可能会显示不同的结果,这只是帮助您的示例。

    在主目录中创建一个名为 .htaccess 的文件 不要触摸应用程序文件夹中的 htaccess

    Options +FollowSymLinks
    Options -Indexes
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    我在实时服务器上使用相同的 htaccess 没有问题 Hosting Provider http://www.arvixe.com/9875-0-1-370.html

    从 config.php 中删除 index.php $config['index_page'] = '';

    此外,如果您有任何包含 index.php 的链接,请删除该示例。

    base_url('index.php/route-name');
    

    更改为

    base_url('route-name');
    

    或者

    site_url('index.php/route-name');
    

    更改为

    site_url('route-name');
    

    如果您仍然遇到问题,请检查您的 routes.php,确保您已在 application/config/route.php $route['name'] = "route-name/index"; 中配置您的路由,请检查您的控制器名称。

    在 codeigniter 3.0 中,您还需要将控制器大写。示例 Welcome.php

    如果这不起作用,我发现 https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter 有大约 5 个示例,您可以根据您的服务器/操作系统系统尝试

    【讨论】:

    • Thanx Mustang,但它对我不起作用,它告诉我禁止访问。我错过了什么吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-27
    • 2018-08-11
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2016-11-12
    相关资源
    最近更新 更多