首页 > 解决方案 > .htaccess 文件在我的 codeigniter 应用程序中导致禁止错误,我在我的 Windows 服务器中运行 apache 24

问题描述

如果没有 .htaccess 文件,应用程序运行完美,每当我添加 .htaccess 文件时,它显示禁止访问 / 服务器。我试着输入“测试”。在 .htaccess 文件的第一行中,它“显示内部服务器错误”这是很好的 apache 读取 .htaccess 文件。但是,每当它立即读取 .htaccess 文件中的“RewriteEngine on”行时,它就会显示禁止错误。

这是我的 .htaccess 文件。

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

和 httpd.config 文件

   DocumentRoot "${SRVROOT}/htdocs"
   <Directory "${SRVROOT}/htdocs">
   #
   # Possible values for the Options directive are "None", "All",
   # or any combination of:
   #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
   #
   # Note that "MultiViews" must be named *explicitly* --- "Options All"
   # doesn't give it to you.
   #
   # The Options directive is both complicated and important.  Please see
   # http://httpd.apache.org/docs/2.4/mod/core.html#options
   # for more information.
   #
   Options Indexes FollowSymLinks

   #
   # AllowOverride controls what directives may be placed in .htaccess files.
   # It can be "All", "None", or any combination of the keywords:
   #   AllowOverride FileInfo AuthConfig Limit
   #
   AllowOverride All

   #
   # Controls who can get stuff from this server.
   #
   Require all granted
   Options ExecCGI 
   </Directory>

标签: windowsapache.htaccesscodeigniter

解决方案


  1. 无需更改httpd.conf文件,.htaccess文件足以使您的CI项目启动并运行。
  2. 但如果你必须,你需要给出绝对路径,DocumentRoot即更改${SRVROOT}/htdocs"F:/xampp/htdocs" -- (your/location/here)
  3. ${SRVROOT}将无法工作,因为您没有在.php文件中写入。

有关更多信息,请参阅这些-

这是我的httpd.conf文件-

DocumentRoot "F:/xampp/htdocs"
<Directory "F:/xampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

我的.htaccess——

RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1  
# if your base_url() doesn't have a trailing slash then instead of ↑ use ↓- 
# RewriteRule (.*) /index.php/$1

希望这对您有所帮助。


推荐阅读