Php 我的.htaccess文件有什么问题,它可以在linux上工作?

Php 我的.htaccess文件有什么问题,它可以在linux上工作?,php,linux,.htaccess,codeigniter,Php,Linux,.htaccess,Codeigniter,我在codeigniter中有一个项目,我有一个.htaccess文件,用于向用户隐藏index.php页面。在本地机器上,当项目在windows操作系统中运行时,但当我在linux(ubuntu发行版)中测试时,.htaccess特性不起作用。任何关于我可以为linux做些什么的建议都非常感谢。 我的.htaccess文件: <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /myproject/

我在codeigniter中有一个项目,我有一个.htaccess文件,用于向用户隐藏index.php页面。在本地机器上,当项目在windows操作系统中运行时,但当我在linux(ubuntu发行版)中测试时,.htaccess特性不起作用。任何关于我可以为linux做些什么的建议都非常感谢。 我的.htaccess文件:

<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /myproject/

    ### 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|myproject) [NC]
   RewriteRule ^(.*)$ http://localhost/myproject/$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]

</IfModule>

<IfModule !mod_rewrite.c>

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

</IfModule>

重新启动发动机
重写数据库/我的项目/
###规范化codeigniter URL
#如果您的默认控制器不是
#“欢迎”您可能应该更改此选项
重写规则^(平台(/索引)?/?$/[L,R=301]
重写规则^(.*)/索引/?$$1[L,R=301]
#删除尾部斜杠(防止SEO重复内容问题)
重写cond%{REQUEST_FILENAME}-D
重写规则^(+)/$$1[L,R=301]
#强制执行www
#如果您有子域,可以将它们添加到
#使用“|”(或)正则表达式运算符的列表
重写cond%{HTTP_HOST}^(localhost | myproject)[NC]
重写规则^(.*)$http://localhost/myproject/$1[L,R=301]
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
#在没有mod_重写的情况下,将404路由到前控制器
ErrorDocument 404/index.php

原因有很多,但我总是先检查:

允许超限

检查主Apache配置。默认情况下,对于文档根目录,AllowOverride指令可能设置为none。在这种情况下,Apache将忽略htaccess文件

模块缺失

因为您的命令包装在IfModule语句中。如果您的Linux设备没有该模块,则不会执行该命令

提示

要查看是否正在读取htacess,只需在任何ifmodule语句之外的文件顶部添加一些废话,例如“dkwei239d”或任何不合法的指令

您应该得到一个500服务器错误。如果没有,则Apache没有读取.htaccess文件

如果出现500错误,则Apache正在读取该文件


尝试删除Ifmodule语句。如果返回错误,则可能缺少“重写”模块

就在我刚开始添加这个非SE字符串GFG时,应用程序崩溃,服务器遇到内部错误或配置错误,无法完成您的请求。请与服务器管理员联系,webmaster@localhost并告知他们错误发生的时间,以及您可能采取的任何可能导致错误的措施。有关此错误的详细信息,请参阅服务器错误日志。Apache/2.2.22(Ubuntu)服务器的端口为49131,因此重写将是不可能的,因为这是在linux服务器上托管之后发生的。然后,为了测试这个错误,我使用了一台本地linux机器,错误是一样的!