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 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记