Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么.htaccess文件mod_rewrite无法工作?_Php_Apache_.htaccess_Codeigniter_Mod Rewrite - Fatal编程技术网

Php 为什么.htaccess文件mod_rewrite无法工作?

Php 为什么.htaccess文件mod_rewrite无法工作?,php,apache,.htaccess,codeigniter,mod-rewrite,Php,Apache,.htaccess,Codeigniter,Mod Rewrite,我正在使用MAMP和CodeIgniter。 我的网站的根目录是:/Users/Roy/Websites/CodeIgniter-3.0.2 在“网站”文件夹中,我还有一些其他项目,但我认为这并不重要。以下是apache httpd.conf文件: 在.htaccess文件中,我使用了以下内容: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule

我正在使用MAMP和CodeIgniter。 我的网站的根目录是:/Users/Roy/Websites/CodeIgniter-3.0.2 在“网站”文件夹中,我还有一些其他项目,但我认为这并不重要。以下是apache httpd.conf文件:

在.htaccess文件中,我使用了以下内容:

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

<IfModule authz_core_module>
   Require all denied
</IfModule>
<IfModule !authz_core_module>
   Deny from all
</IfModule>
重新编写引擎打开
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]
要求全部拒绝
全盘否定
.htaccess文件位于:/Users/Roy/Websites/CodeIgniter-3.0.2/.htaccess 我不知道为什么mod_重写不起作用,它应该消除在url中使用index.php,因为我现在必须使用的url是:


我希望变成:使用PHP版本5.6.10apache没有读取.htaccess文件,这就是问题所在,如何修复它?

这可能是因为您在httpd.conf文件中将文档根目录设置为
/Users/Roy/Websites/
。就我个人而言,如果您计划拥有多个网站,这样每个网站都可以拥有自己的
.conf
,并且您可以专门为每个网站设置文档根目录,我会使用
virtualhosts

总之,现在您的
CodeIgniter-3.0.2
网站的子文件夹,它是您的文档根目录。所以很可能是重写库有问题

如果您的文件和.htaccess位于codeigniter文件夹中,则.htaccess需要如下所示

RewriteEngine On
RewriteBase /CodeIgniter-3.0.2
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
你可以用这个

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /Project_Name
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

重新启动发动机
重写基础/项目名称
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
ErrorDocument 404/index.php

问题解决后,安装了MAMP的httpd.conf就没有必要弄乱了。只需获取CodeIgniter并将其放在MAMP中的htdocs文件夹中。之后,在CodeIgniter文件夹(而不是其中的应用程序文件夹)内创建一个.htaccess文件,并使用以下代码:

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /ci/
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

重新启动发动机
重写库/ci/
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php/$1[L]

现在您有了干净的URL,不再需要使用/index.php/about,只需执行/about即可。

看起来像是文件权限问题。签出.htaccess文件的属性并更改权限

请尝试使用此代码

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

要了解更多信息,请尝试。htaccess可能会非常令人沮丧。多看看真正有用的东西

1.您的.htaccess应该如下所示

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /booking/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>
五,

六,

七,。通过删除此行前面的#,在httpd.conf文件中启用Mod rewrite

LoadModule rewrite_module modules/mod_rewrite.so

我希望这能解决您的问题

当不使用index.php时,您会得到什么消息?谢谢您的建议,但是当我将所有内容粘贴到.htaccess文件中并重新启动MAMP以确保仍然得到相同的信息时。当使用“我看到我的网页”时,但当我使用“我从CodeIgniter获得默认的未找到页面”时,这里有一个屏幕截图:您是否将CI配置更新为此
$config['index_page']=''
重新启动MAMP后,尝试使rewriterule
rewriterule^(.*)$/CodeIgniter-3.0.2/index.php/$1[L]
仍然是同一个页面,似乎它甚至没有读取此.htaccess文件。也许我应该检查错误日志?检查错误日志,并在.htaccess文件顶部输入随机文本。它不会给你一个500错误,它没有读取它。感谢你的输入russel,但是由于某种原因,整个.htaccess文件没有被读取。
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
LoadModule rewrite_module modules/mod_rewrite.so