dtlhy0771 2014-06-12 14:32
浏览 59
已采纳

htaccess导致重定向循环

So I migrated my app from one host to another. Most of the app works through 'pretty urls' where /login.php becomes /login (which I access in my php through $_SERVER['REQUEST_URI'] ), however after switching hosts my htaccess code for this doesn't work anymore (chrome gives me a redirect loop error).

This is the code:

 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  

Any idea what could be wrong?

  • 写回答

1条回答 默认 最新

  • dsh8009271 2014-06-12 14:36
    关注

    If you want to redirect HTTP to 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
    

    If you want to redirect HTTPS to 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历