0

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>
MrTux
  • 32,350
  • 30
  • 109
  • 146

1 Answers1

0

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

MrTux
  • 32,350
  • 30
  • 109
  • 146
  • Thank you sou much, can i have following question ? /n If i remember it correct, if there are RewriteCond next to each other it is same like if i use && in if right ? and any RewriteRule will be apllyed if all Cond are true until there will be next RewriteCond after RewriteRule ? – JonatanRek Jul 23 '19 at 18:38