# Production Static Files Fix - Deployment Guide

## Problem
When `DEBUG = False` in production, static files (CSS, JavaScript, images) are not loading, causing:
- Client names to appear stacked on top of each other
- Missing images and styling
- Broken layout

## Solution
The issue was with the `.htaccess` configuration and static file serving. We've fixed:

1. **Updated `.htaccess`** - Fixed the static file rewrite rules
2. **Corrected `settings_production.py`** - Fixed STATIC_ROOT and removed STATICFILES_DIRS conflict
3. **Collected all static files** - All files are now in the `staticfiles` directory

## Files to Upload to cPanel

### 1. Updated Settings File
- `branch_system/settings_production.py` (with the fixes)

### 2. Updated .htaccess
- `.htaccess` (with the corrected static file rules)

### 3. Static Files Directory
- Upload the entire `staticfiles/` directory to your cPanel
- Make sure it's in the same directory as your `passenger_wsgi.py` file

### 4. Media Files Directory
- Upload the entire `media/` directory to your cPanel

## Deployment Steps

1. **Upload the files** to your cPanel file manager
2. **Restart your web server** in cPanel
3. **Test your website**:
   - Main site: https://branchbusinessadvance.co.ke/
   - Admin: https://branchbusinessadvance.co.ke/admin/
   - Test static file: https://branchbusinessadvance.co.ke/static/admin/css/base.css

## Key Changes Made

### .htaccess Fix
```apache
# Handle static files - serve from staticfiles directory
RewriteCond %{REQUEST_URI} ^/static/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^static/(.*)$ staticfiles/$1 [L]
```

### Settings Fix
```python
# Static and Media Files
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
# Remove STATICFILES_DIRS in production to avoid conflict with STATIC_ROOT
STATICFILES_DIRS = []
```

## Troubleshooting

If static files still don't work after deployment:

1. **Check file permissions** - Make sure the web server can read the staticfiles directory
2. **Verify file locations** - Ensure staticfiles is in the correct directory
3. **Check cPanel error logs** - Look for any Apache or Django errors
4. **Test with alternative .htaccess rule**:
   ```apache
   RewriteRule ^static/(.*)$ /staticfiles/$1 [L]
   ```

## Expected Result
After deployment, you should be able to:
- Set `DEBUG = False` in production
- See properly styled pages with client names displayed correctly
- See all images loading properly
- Have a fully functional admin interface

## File Count
- Total static files collected: 127+ files
- Key files include: admin CSS/JS, logo.png, custom JS files 