【问题标题】:codeigniter - what's wrong with my htaccess?codeigniter - 我的 htaccess 有什么问题?
【发布时间】:2017-07-24 23:54:23
【问题描述】:

我正在尝试使用 PHP 和 MySQL 在本地构建购物车。我的站点的主目录是 /Library/WebServer/Documents。我试图设置它,以便我可以在没有 index.php 的情况下访问 localhost/project。

这是我的 htaccess:

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
</IfModule>
<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
</IfModule>

我的配置代码(提取,不是全部):

$config['base_url'] = 'http://localhost/project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

显然这里有一个错误。即使我设法在没有 index.php 的情况下访问 localhost/project,我也无法查看由我的控制器代码生成的页面(例如,如果我尝试访问 localhost/project/welcome,我会收到以下错误消息:'The在此服务器上找不到请求的 URL /project/welcome。' localhost/project/welcome 应该将我带到我的控制器文件夹下的 Welcome.php 页面。

Here's a snapshot of the file structure

有人可以向我解释我的代码有什么问题吗?

【问题讨论】:

  • 通常情况下,views 目录中不会有 .htaccess 文件。至少在全新的 CI 安装中没有这样的文件。
  • @vnguyen 你需要从 Url 中删除 index.php 吗??

标签: php mysql apache .htaccess codeigniter


【解决方案1】:

你的意思是没有.php?

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

删除这个 DirectoryIndex index.php! 它将 index.php 设置在 url 后面

【讨论】:

  • 谢谢,已修复!
【解决方案2】:

使用这个.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #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>

【讨论】:

    猜你喜欢
    • 2013-07-17
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 2011-01-09
    • 2012-11-12
    • 1970-01-01
    • 2016-10-06
    • 1970-01-01
    相关资源
    最近更新 更多