Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.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导致重定向循环_Php_.htaccess_Redirect - Fatal编程技术网

Php htaccess导致重定向循环

Php htaccess导致重定向循环,php,.htaccess,redirect,Php,.htaccess,Redirect,因此,我将我的应用程序从一个主机迁移到另一个主机。大多数应用程序通过'pretty url'工作,其中/login.php变为/login(我在php中通过$_服务器['REQUEST\u URI']访问它),但是在切换主机后,我的htaccess代码不再工作(chrome给我一个重定向循环错误) 代码如下: Options +FollowSymLinks RewriteEngine On RewriteCond %{SERVER_PORT} ^80$ RewriteR

因此,我将我的应用程序从一个主机迁移到另一个主机。大多数应用程序通过'pretty url'工作,其中/login.php变为/login(我在php中通过$_服务器['REQUEST\u URI']访问它),但是在切换主机后,我的htaccess代码不再工作(chrome给我一个重定向循环错误)

代码如下:

 Options +FollowSymLinks  
 RewriteEngine On  

 RewriteCond     %{SERVER_PORT} ^80$
 RewriteRule     ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]

 RewriteCond %{SCRIPT_FILENAME} !-d  
 RewriteCond %{SCRIPT_FILENAME} !-f  

 RewriteRule ^.*$ ./index.php  

知道有什么问题吗?

如果要将HTTP重定向到HTTPS:

RewriteCond     %{SERVER_PORT} ^80$
RewriteRule     ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond     %{SCRIPT_FILENAME} !-d  
RewriteCond     %{SCRIPT_FILENAME} !-f
RewriteRule     ^(.*)$ index.php/$1

如果要将HTTPS重定向到HTTP:

RewriteCond     %{SERVER_PORT} ^443$
RewriteRule     ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R]

RewriteCond     %{SCRIPT_FILENAME} !-d  
RewriteCond     %{SCRIPT_FILENAME} !-f
RewriteRule     ^(.*)$ index.php/$1

你能解释一下重写cond%{SERVER\u PORT}^80$RewriteRule^(.*)$http://%{SERVER\u NAME}%{REQUEST\u URI}[L,R]的作用吗?它对我来说完全没有用…@Peter
RewriteCond%{SERVER\u PORT}^80$
=在端口80上查找任何连接
RewriteRule^(.*)$http://%{SERVER_NAME}%{REQUEST_URI}[L,R]
=将所有内容
^(.*)$
重写到
http://%{SERVER_NAME}%{REQUEST_URI}
并将其作为
[L]
最后一条规则,即
[R]
重定向。如果你想让它永久化,将[L,R]改为[L,R=303]`303是'moved permanently'的HTTP代码@OCIA我理解语法,如果端口80上有连接,将它重定向到端口HTTP://,默认端口(80)=无用,无限循环编辑几次,以匹配问题的来源(包括对
重写规则^(.*)$index.php/$1
的更改)