【发布时间】:2014-03-04 09:38:34
【问题描述】:
我正在 codeIgniter 中创建一个项目,使用 wamp 在本地开发 (Apache 2.4)。在整个项目中,我打开了 mod_rewrite 以删除默认情况下出现在 codeigniter 的 url 中的 index.php,方法是使用 codeigniter 项目目录中的 .htaccess 文件,即 C:\wamp\www\codeIgniter\.htaccess。
我们需要在应用程序中进行 Windows 身份验证,因此在最终设法使 ldap 和 sspi 模块正常工作后,我将以下内容应用于 c:wamp\bin\apache\Apache2.4.4\conf\httpd.conf 中的 httpd.conf 文件
<Directory "c:/wamp/www/codeIgniter">
AllowOverride None
Options None
Order allow,deny
Allow from all
AuthName "protected"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIOmitDomain On
require valid-user
</Directory>
我得到了这个配置here。
对httpd.conf 文件进行这些更改后,mod_rewrite 规则似乎不再适用,我必须在项目根目录后写入index.php 以获取要加载的网址。
在阅读了一些关于设置 httpd.conf 配置和 .htaccess 文件的 Apache 文档后,它建议如果可以访问服务器配置,则不应使用 .htaccess 文件:
一般来说,您应该只在没有 .htaccess 文件时使用 访问主服务器配置文件。例如,有一个 用户身份验证应始终在 .htaccess 文件,以及近年来的另一个误解,即 mod_rewrite 指令必须放在 .htaccess 文件中。这根本不是 案子。您可以将用户身份验证配置放在主 服务器配置,事实上,这是首选的方式 事物。同样,mod_rewrite 指令在许多情况下工作得更好 方面,在主服务器配置中。 Link
首先我想了解如何让我的 mod_rewrite 规则与我的 sspi 内容一起愉快地再次工作,其次如何将我的 mod_rewrite 规则从 .htaccess 移动到我的服务器配置文件 httpd.conf.
我已经尝试在服务器配置中切换AllowOverride All,就像上面提到的代码一样,但这似乎使一切都无法访问。我也尝试将Order allow,deny 和Allow from all 更改为Require all granted,但这似乎也会导致类似的问题。将我的 mod_rewrite 规则添加到服务器配置中也会导致所有内容都无法访问。任何指导将不胜感激!谢谢。
我的.htaccess如下:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /codeIgniter
#RewriteBase /codeIgniter
#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 acces 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 !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
【问题讨论】:
标签: apache .htaccess codeigniter mod-rewrite sspi