Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.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 url重写不起作用?_Php_.htaccess_Codeigniter_Mod Rewrite - Fatal编程技术网

Php 为什么.htaccess url重写不起作用?

Php 为什么.htaccess url重写不起作用?,php,.htaccess,codeigniter,mod-rewrite,Php,.htaccess,Codeigniter,Mod Rewrite,[编辑]:重复的[那里的解决方案对我不起作用] 我是第一次尝试codeigniter,我对php还是相当陌生的。 我想从我的url中删除index.php 已安装代码点火器 将那里的index.php替换为我自己的 我的.htaccess中有这个 <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILEN

[编辑]:重复的
[那里的解决方案对我不起作用]

我是第一次尝试codeigniter,我对php还是相当陌生的。 我想从我的url中删除index.php

已安装代码点火器
将那里的index.php替换为我自己的

我的.htaccess中有这个

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

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


#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 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>
# 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
</IfModule>
我得到:

这也不起作用(我知道,他们都打算做几乎相同的事情):


试试这段非常简单的代码它对我来说很好:

将项目文件夹的名称改为project2更改您的配置基础_url=“”


试试这段非常简单的代码它对我来说很好:

将项目文件夹的名称改为project2更改您的配置基础_url=“”

然后,htaccess:

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [QSA,L] 
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
我还注意到你说“用我自己的index.php替换了那里的index.php” 这是错误的,请将原始Codeigniter index.php文件保留在 主根,否则您将永远不会运行codeigniter:D

然后,htaccess:

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [QSA,L] 
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
我还注意到你说“用我自己的index.php替换了那里的index.php” 这是错误的,请将原始Codeigniter index.php文件保留在 主根,否则您将永远不会运行codeigniter:D


希望这对你有帮助

您面临的问题是,您删除了index.php,并将其替换为自己的index.php

而是将codeigniter文件夹放在本地主机上,并将index.php放在 [在本地主机上,在浏览器中打开以下url

http://localhost:8888/domain/index.php/welcome
如果工作正常,意味着显示codeigniter的欢迎页面,那么您可以考虑通过添加

RewriteEngine on
RewriteCond $1 !^(index\.php|static)
RewriteRule ^(.*)$ /index.php/$1 [L]
在.htaccess文件中,重写条件的第二行将确保重写规则不会执行,当url中有index.php或static时,使用static可以将所有静态内容放在static文件夹中

现在,当url中没有index.php或static时,重写规则将重写它

假设url是

http://localhost:8888/domain/welcome
将重写为

http://localhost:8888/domain/index.php/welcome

在任何情况下,您的代码都将仅通过包含index.php的url提供。

希望这对您有所帮助

您面临的问题是,您删除了index.php,并将其替换为自己的index.php

而是将codeigniter文件夹放在本地主机上,并将index.php放在 [在本地主机上,在浏览器中打开以下url

http://localhost:8888/domain/index.php/welcome
如果工作正常,意味着显示codeigniter的欢迎页面,那么您可以考虑通过添加

RewriteEngine on
RewriteCond $1 !^(index\.php|static)
RewriteRule ^(.*)$ /index.php/$1 [L]
在.htaccess文件中,重写条件的第二行将确保重写规则不会执行,当url中有index.php或static时,使用static可以将所有静态内容放在static文件夹中

现在,当url中没有index.php或static时,重写规则将重写它

假设url是

http://localhost:8888/domain/welcome
将重写为

http://localhost:8888/domain/index.php/welcome

在任何情况下,您的代码都将仅通过包含index.php的url提供。

我将自己的索引替换为默认的CI索引(即,我将其返回到开箱即用的方式)。
然后我将
域/index.php/pages/view/page.php
路由到
域/index.php/page.php

然后,我运行了Nishant的.htaccess代码,尽管它似乎不起作用(网站的静态非风格版本显示在通常的url上,但不显示在没有index.php的url上)这可能帮助我找到了一个解决方案。
我还将
RewriteEngine On
更改为
RewriteEngine On
,尽管我很确定我以前试过。 在这些步骤之后,我又回到了sbaaang建议的代码(这是一个版本id,以前已经尝试过了,但没有成功),这次它成功了。

对于任何其他可能遇到.htaccess麻烦的人,我建议他们把东西从盒子里拿出来,然后翻阅图坦卡门(而不是像我那样跳进去)

我的.htaccess就这样结束了

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


<Files "index.php">
AcceptPathInfo On
</Files>  
</IfModule>

<IfModule !mod_rewrite.c>

ErrorDocument 404 /index.php
</IfModule>

我用默认的CI索引替换了我自己的索引(即,我将其返回到开箱即用的状态)。
然后我将
domain/index.php/pages/view/page.php
路由到
domain/index.php/page.php

然后,我运行了Nishant的.htaccess代码,尽管它似乎不起作用(网站的静态非风格版本显示在通常的url上,但不显示在没有index.php的url上)这可能帮助我找到了一个解决方案。
我还将
RewriteEngine On
更改为
RewriteEngine On
,尽管我很确定我以前试过。 在这些步骤之后,我又回到了sbaaang建议的代码(这是一个版本id,以前已经尝试过了,但没有成功),这次它成功了。

对于任何其他可能遇到.htaccess麻烦的人,我建议他们把东西从盒子里拿出来,然后翻阅图坦卡门(而不是像我那样跳进去)

我的.htaccess就这样结束了

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


<Files "index.php">
AcceptPathInfo On
</Files>  
</IfModule>

<IfModule !mod_rewrite.c>

ErrorDocument 404 /index.php
</IfModule>

我想
http:8888/domain/
应该是
http://domain:8888/
base\u url中,但我不确定。很抱歉,这是一个typeo,但它没有解决问题:它现在是:$config['base\u url']='localhost:8888/domain.com/';事实上,我刚刚注意到,转到domain/welcome会显示错误消息:在此服务器上找不到请求的URL/index.php/welcome。为什么要用自己的URL/index.php替换index.php?您不必删除index.php,只需编辑默认控制器名称和路由路径。是的,我也注意到了。b但是这些.htaccess黑客并没有将domain/index.php/welcome或domain/index.php/welcome.php发送到domain/welcome,这是他们应该正确的吗?哦,好吧。所以我想他们只会在适当的路由下工作?我猜
http:8888/domain/
需要
http://domain:88