【问题标题】:htaccess and httpd.conf configuraion to enable codeigniter working on ubuntu 12.04htaccess 和 httpd.conf 配置以使 codeigniter 在 ubuntu 12.04 上工作
【发布时间】:2012-10-27 20:28:58
【问题描述】:

我已经安装了 ubuntu 12.04,并且我有运行 php 项目的完整要求(apache、mysql 和 php5)。不在 codeigniter 中的项目运行良好。在 codeigniter 中,当我加载项目时,默认控制器会加载 index_view 但是当我单击其他控制器时;他们不会出现错误并显示错误

未找到 在此服务器上未找到请求的 URL /academic/login。

我意识到 .htaccess 不起作用;然后 /etc/apache2/httpd.conf 文件为空 我想请求 httpd.conf 文件的基本配置示例,以便我的 htaccess 文件可以工作。如果有任何建议可以帮助我得出一些结果,我们将不胜感激。谢谢。 我的 httaccess 在下面给出

RewriteEngine On
RewriteBase /

### Canonicalize codeigniter URLs

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(platform(/index)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]

# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(localhost|academic) [NC]
RewriteRule ^(.*)$ http://localhost/academic/$1 [L,R=301]

# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]

###

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

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

# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php

【问题讨论】:

    标签: .htaccess codeigniter apache2 ubuntu-12.04


    【解决方案1】:

    这个值得信赖的人从来没有亏待过我:

    RewriteEngine On
    RewriteBase /academic/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/ [L]
    ErrorDocument 404 /index.php
    

    【讨论】:

    • +1 但ErrorDocument 404 /index.php 是不必要的。如果有人提供了无效的路径,它无论如何都会通过 index.php (至少结合你之前的规则)。
    • 谢谢,我意识到我在 Windows 中的 htaccess 可以在 ubuntu 12.04 中与 RewriteBase /academic/ 一起正常工作,但可以在 ubuntu 中工作;还有一些其他配置:a2enmod rewrite 命令、apache2 配置文件httpd.conf/etc/apache2/sites-available/default 其中 AllowOverride All 替换 AllowOverride None。谢谢。
    猜你喜欢
    • 2022-10-14
    • 2013-01-28
    • 2013-09-14
    • 2012-06-27
    • 2012-06-19
    • 2011-11-01
    • 1970-01-01
    • 2013-12-06
    • 2020-06-19
    相关资源
    最近更新 更多