dongqiang5541 2019-07-23 17:53
浏览 31
已采纳

api.php的Htaccess异常

My NodeMCU is saving data to my web server (temperature, humidity, etc) but after i rewrite my server front end and back-end to use symphony framework i am unable to get access to my API file over HTTP even when i have exception written in my .htaccess

MY .htaccess

RewriteEngine On
RewriteBase /vasek/home/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.css
RewriteCond %{REQUEST_FILENAME} !.js
RewriteCond %{REQUEST_FILENAME} !api.php
RewriteRule (.*) index.php?url=$1 [QSA,L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

i expect to access api.php file in root folder of my server instead get this

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://dev.steelants.cz/vasek/home/api.php">here</a>.</p>
<hr>
<address>Apache/2.4.25 (Debian) Server at dev.steelants.cz Port 80</address>
</body></html>
  • 写回答

1条回答 默认 最新

  • dongnang8192 2019-07-23 18:02
    关注

    The redirect above is caused by the HTTP to HTTPS redirect which is caused by the second rule. If you don't want to have it, see the following:

    RewriteEngine On
    RewriteBase /vasek/home/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !.css
    RewriteCond %{REQUEST_FILENAME} !.js
    RewriteRule (.*) index.php?url=$1 [QSA,L]
    
    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_FILENAME} !api.php
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    RewriteCond %{REQUEST_FILENAME} !api.php is not necessary for the first RewriteRule as it is already included in !-f (cf. https://httpd.apache.org/docs/current/mod/mod_rewrite.html; I suppose that the other two rules for !.css and !.js are also not necessary). However, you want this exception for the HTTPS redirect.

    Btw. you should avoid permanent redirects (cf. How to undo a 301 redirect?).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)