# Make Root Domain Redirect to Frontend

Make `https://herataria.nova.af/` automatically go to the login page.

---

## Option 1: .htaccess Redirect (Recommended)

### Step 1: Create .htaccess File

In cPanel File Manager:

1. Navigate to `public_html/` (root folder)
2. Click **New File**
3. Name it: `.htaccess` (with the dot at the beginning!)
4. Click **Create New File**

### Step 2: Edit .htaccess

1. Right-click `.htaccess` → **Edit**
2. Paste this code:

```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Redirect root to frontend
    RewriteRule ^$ /frontend/ [L,R=301]
    RewriteRule ^index\.html$ /frontend/ [L,R=301]

    # Don't touch backend requests
    RewriteCond %{REQUEST_URI} ^/backend/
    RewriteRule ^ - [L]

    # Don't touch existing files/folders
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    # Redirect everything else to frontend
    RewriteCond %{REQUEST_URI} !^/frontend/
    RewriteRule ^(.*)$ /frontend/$1 [L,R=301]
</IfModule>
```

3. Click **Save Changes**
4. Close the editor

### Step 3: Test

Visit: `https://herataria.nova.af/`

**Expected:** Automatically redirects to `https://herataria.nova.af/frontend/#/login`

---

## Option 2: Simple HTML Redirect (If .htaccess doesn't work)

### Step 1: Create index.html

In cPanel File Manager:

1. Navigate to `public_html/` (root folder)
2. Click **New File**
3. Name it: `index.html`
4. Click **Create New File**

### Step 2: Edit index.html

1. Right-click `index.html` → **Edit**
2. Paste this code:

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="refresh" content="0; url=/frontend/#/login">
    <title>Redirecting...</title>
    <script>
        window.location.href = '/frontend/#/login';
    </script>
</head>
<body>
    <p>Redirecting to Aria Herat ERP...</p>
    <p>If you are not redirected, <a href="/frontend/#/login">click here</a>.</p>
</body>
</html>
```

3. Click **Save Changes**
4. Close the editor

### Step 3: Test

Visit: `https://herataria.nova.af/`

**Expected:** Redirects to login page

---

## Option 3: Move Frontend to Root (Advanced)

If you want `https://herataria.nova.af/` to be the frontend (no `/frontend/` in URL):

### Step 1: Move Files

In cPanel File Manager:

1. Go to `public_html/frontend/`
2. Select ALL files (index.html, assets/, icons/, etc.)
3. Click **Move** (top toolbar)
4. Move to: `/public_html/`
5. Confirm move

### Step 2: Update .htaccess in Root

Create/edit `public_html/.htaccess`:

```apache
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # Redirect /api requests to backend
    RewriteCond %{REQUEST_URI} ^/api/
    RewriteRule ^api/(.*)$ /backend/public/api/$1 [L,QSA]

    # Don't touch backend folder
    RewriteCond %{REQUEST_URI} ^/backend/
    RewriteRule ^ - [L]

    # Handle frontend SPA routing
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ /index.html [L]
</IfModule>
```

### Step 3: Update Frontend API URL

You'll need to rebuild frontend with new API URL:

1. Edit `frontend/.env.production`:
   ```
   VITE_API_URL=https://herataria.nova.af/api
   ```

2. Rebuild:
   ```bash
   cd frontend
   npm run build
   ```

3. Upload new files to `public_html/` (root, not `/frontend/`)

### URLs After This Change:
- Frontend: `https://herataria.nova.af/`
- Backend API: `https://herataria.nova.af/api/login` etc.
- Backend folder still at: `public_html/backend/`

---

## Which Option to Choose?

### Choose Option 1 (.htaccess) if:
- ✅ You want simple redirect
- ✅ Keep folder structure organized
- ✅ Easy to update later

### Choose Option 2 (HTML redirect) if:
- ✅ .htaccess doesn't work on your server
- ✅ Want simplest solution
- ✅ Don't have Apache mod_rewrite

### Choose Option 3 (Move to root) if:
- ✅ Want cleaner URLs (no `/frontend/`)
- ✅ Willing to rebuild frontend
- ✅ Want professional deployment

**My Recommendation:** Start with **Option 1** (.htaccess) - it's simple and works!

---

## Troubleshooting

### .htaccess not working?

**Check if mod_rewrite is enabled:**
- Contact your hosting support
- Or try Option 2 (HTML redirect)

### Redirect loop?

**Check for conflicting .htaccess files:**
- Only have one `.htaccess` in `public_html/`
- Delete any `.htaccess` in `public_html/frontend/`

### Backend stops working?

**Make sure backend path is excluded:**
```apache
# Add this before other rules
RewriteCond %{REQUEST_URI} ^/backend/
RewriteRule ^ - [L]
```

---

## Current vs After Fix

**Current:**
- User types: `herataria.nova.af`
- Must manually go to: `herataria.nova.af/frontend/#/login`

**After Fix (Option 1 or 2):**
- User types: `herataria.nova.af`
- Automatically redirected to: `herataria.nova.af/frontend/#/login`

**After Fix (Option 3):**
- User types: `herataria.nova.af`
- Already there! Shows login page
- URL stays: `herataria.nova.af/#/login` (cleaner!)

---

## Quick Start

**Do this now (easiest):**

1. In cPanel File Manager, go to `public_html/`
2. Create new file: `.htaccess`
3. Paste the code from Option 1
4. Save
5. Test by visiting `herataria.nova.af`

Done! ✅
