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?).

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

报告相同问题?