Ganti index.php menjadi index.html untuk menghindari redirect loop PHP

This commit is contained in:
mwpn
2025-12-18 13:36:36 +07:00
parent 6b1de8830d
commit c4d4d65882
8 changed files with 22 additions and 12 deletions

View File

@@ -3,8 +3,9 @@
## Masalah ## Masalah
Dari curl test: Dari curl test:
``` ```
HTTP/2 302 HTTP/2 302
location: ../index.php location: ../index.php
``` ```
@@ -39,11 +40,13 @@ cat /etc/nginx/conf.d/retribusi.conf
``` ```
Pastikan ada: Pastikan ada:
```nginx ```nginx
root /www/wwwroot/retribusi.btekno.cloud/retribusi/public; root /www/wwwroot/retribusi.btekno.cloud/retribusi/public;
``` ```
**BUKAN**: **BUKAN**:
```nginx ```nginx
root /www/wwwroot/retribusi.btekno.cloud/retribusi; # SALAH! root /www/wwwroot/retribusi.btekno.cloud/retribusi; # SALAH!
``` ```
@@ -79,4 +82,3 @@ Seharusnya sekarang tidak ada redirect 302 lagi.
- [ ] Nginx sudah di-reload - [ ] Nginx sudah di-reload
- [ ] Test curl tidak ada redirect 302 - [ ] Test curl tidak ada redirect 302
- [ ] Browser cache sudah di-clear - [ ] Browser cache sudah di-clear

View File

@@ -50,7 +50,7 @@ File `public/dashboard/js/config.js` mengatur:
1. Pastikan backend API sudah running 1. Pastikan backend API sudah running
2. Set document root ke folder `public/` 2. Set document root ke folder `public/`
3. Buka `index.php` untuk login (atau akses root `/`) 3. Buka `index.html` untuk login (atau akses root `/`)
4. Akses dashboard di `dashboard/dashboard.html` 4. Akses dashboard di `dashboard/dashboard.html`
## Production ## Production

View File

@@ -237,12 +237,14 @@
// Check auth // Check auth
if (!Auth.isAuthenticated()) { if (!Auth.isAuthenticated()) {
const currentPath = window.location.pathname.toLowerCase(); const currentPath = window.location.pathname.toLowerCase();
const isLoginPage = currentPath.includes('index.php') || const isLoginPage = currentPath.includes('index.html') ||
currentPath.includes('index.php') ||
currentPath === '/' || currentPath === '/' ||
currentPath === '/index.html' ||
currentPath === '/index.php'; currentPath === '/index.php';
// Hanya redirect jika belum di login page // Hanya redirect jika belum di login page
if (!isLoginPage) { if (!isLoginPage) {
window.location.href = '../index.php'; window.location.href = '../index.html';
} }
} }

View File

@@ -42,14 +42,16 @@ async function apiRequest(path, options = {}) {
localStorage.removeItem('user'); localStorage.removeItem('user');
// Cek apakah sudah di login page untuk menghindari redirect loop // Cek apakah sudah di login page untuk menghindari redirect loop
const currentPath = window.location.pathname.toLowerCase(); const currentPath = window.location.pathname.toLowerCase();
const isLoginPage = currentPath.includes('index.php') || const isLoginPage = currentPath.includes('index.html') ||
currentPath.includes('index.php') ||
currentPath === '/' || currentPath === '/' ||
currentPath === '/index.html' ||
currentPath === '/index.php' || currentPath === '/index.php' ||
currentPath.endsWith('/') || currentPath.endsWith('/') ||
currentPath === ''; currentPath === '';
// Hanya redirect jika benar-benar di halaman dashboard, bukan di login page // Hanya redirect jika benar-benar di halaman dashboard, bukan di login page
if (!isLoginPage && currentPath.includes('dashboard')) { if (!isLoginPage && currentPath.includes('dashboard')) {
window.location.href = '../index.php'; window.location.href = '../index.html';
} }
throw new Error('Unauthorized'); throw new Error('Unauthorized');
} }

View File

@@ -23,7 +23,7 @@ export const Auth = {
localStorage.removeItem(TOKEN_KEY); localStorage.removeItem(TOKEN_KEY);
localStorage.removeItem(USER_KEY); localStorage.removeItem(USER_KEY);
sessionStorage.removeItem('auth_redirect_done'); sessionStorage.removeItem('auth_redirect_done');
window.location.href = '../index.php'; window.location.href = '../index.html';
} }
}; };

View File

@@ -697,8 +697,10 @@ document.addEventListener('DOMContentLoaded', async () => {
if (!Auth.isAuthenticated()) { if (!Auth.isAuthenticated()) {
// Cek apakah sudah di login page untuk mencegah redirect loop // Cek apakah sudah di login page untuk mencegah redirect loop
const currentPath = window.location.pathname.toLowerCase(); const currentPath = window.location.pathname.toLowerCase();
const isLoginPage = currentPath.includes('index.php') || const isLoginPage = currentPath.includes('index.html') ||
currentPath.includes('index.php') ||
currentPath === '/' || currentPath === '/' ||
currentPath === '/index.html' ||
currentPath === '/index.php' || currentPath === '/index.php' ||
currentPath.endsWith('/') || currentPath.endsWith('/') ||
currentPath === ''; currentPath === '';
@@ -706,7 +708,7 @@ document.addEventListener('DOMContentLoaded', async () => {
// JANGAN redirect jika sudah di login page atau root // JANGAN redirect jika sudah di login page atau root
if (!isLoginPage && currentPath.includes('dashboard')) { if (!isLoginPage && currentPath.includes('dashboard')) {
// Hanya redirect jika benar-benar di halaman dashboard // Hanya redirect jika benar-benar di halaman dashboard
window.location.href = '../index.php'; window.location.href = '../index.html';
} }
return; return;
} }

View File

@@ -571,12 +571,14 @@
// Check auth // Check auth
if (!Auth.isAuthenticated()) { if (!Auth.isAuthenticated()) {
const currentPath = window.location.pathname.toLowerCase(); const currentPath = window.location.pathname.toLowerCase();
const isLoginPage = currentPath.includes('index.php') || const isLoginPage = currentPath.includes('index.html') ||
currentPath.includes('index.php') ||
currentPath === '/' || currentPath === '/' ||
currentPath === '/index.html' ||
currentPath === '/index.php'; currentPath === '/index.php';
// Hanya redirect jika belum di login page // Hanya redirect jika belum di login page
if (!isLoginPage) { if (!isLoginPage) {
window.location.href = '../index.php'; window.location.href = '../index.html';
} }
} }