# 🔗 HowToMalaysia URL Configuration Guide

## Overview
The URL Configuration section in Admin Settings allows you to set up default URLs for different environments and secure admin access paths.

## Configuration Fields

### 1. **Default Website URL**
- **Purpose**: Main public URL for your website
- **Example**: `https://howtomalaysia.com`
- **Used for**: SEO, email links, social sharing, redirects
- **Requirements**: Must be HTTPS in production

### 2. **Admin Login Page URL**  
- **Purpose**: Secure admin login URL
- **Example**: `https://howtomalaysia.com/admin`
- **Used for**: Admin access, security notifications
- **Requirements**: Should match your custom admin path

### 3. **Development/Testing URL**
- **Purpose**: Local development server
- **Example**: `http://localhost:8000`
- **Used for**: Local testing, development workflow
- **Optional**: Leave empty if not using local development

### 4. **Staging/Preview URL**
- **Purpose**: Staging environment for testing before production
- **Example**: `https://staging.howtomalaysia.com`
- **Used for**: Pre-production testing, client previews
- **Optional**: Only needed if you use staging environment

### 5. **Custom Admin Path**
- **Purpose**: Security enhancement through obscurity
- **Example**: `/secure-admin`, `/dashboard`, `/management`
- **Default**: `/admin`
- **Requirements**: Must start with `/` and contain only letters, numbers, hyphens, underscores

## Security Features

### Force HTTPS for Admin Access
- **Enabled by default**
- Automatically redirects HTTP admin requests to HTTPS
- Protects login credentials and session data

### Pretty URLs (URL Rewriting)
- **Requires .htaccess configuration**
- Converts `/article.php?id=123` to `/article/123`
- Improves SEO and user experience

## Best Practices

### Production Setup
```
Default Website URL: https://howtomalaysia.com
Admin Login URL: https://howtomalaysia.com/secure-admin  
Custom Admin Path: /secure-admin
Force HTTPS: ✅ Enabled
Pretty URLs: ✅ Enabled (with .htaccess)
```

### Development Setup
```
Development URL: http://localhost:8000
Admin Login URL: http://localhost:8000/admin
Custom Admin Path: /admin
Force HTTPS: ❌ Disabled (for local development)
Pretty URLs: ❌ Disabled (optional)
```

### Security Recommendations

1. **Use Unique Admin Path**: Don't use `/admin` in production
2. **Force HTTPS**: Always enable for production sites
3. **Regular Updates**: Change admin path periodically
4. **Access Logs**: Monitor admin login attempts

## Environment-Specific Configuration

### Local Development
- Use `http://localhost:PORT` for development URL
- Admin path can be simple like `/admin`
- HTTPS not required locally

### Staging Environment  
- Use subdomain like `staging.yoursite.com`
- Same security as production
- Can use different admin path for testing

### Production Environment
- Use primary domain with HTTPS
- Secure admin path (not `/admin`)
- Enable all security features

## Troubleshooting

### Common Issues

1. **Admin Page Not Found**
   - Check custom admin path matches file structure
   - Verify .htaccess rules if using pretty URLs

2. **HTTPS Redirect Loop**
   - Check server HTTPS configuration
   - Verify SSL certificate is properly installed

3. **URLs Not Saving**
   - Check database permissions
   - Verify URL format is correct

### Testing URLs

After configuration, test all URLs:

```bash
# Test main website
curl -I https://howtomalaysia.com

# Test admin access  
curl -I https://howtomalaysia.com/your-admin-path

# Test HTTPS redirect
curl -I http://howtomalaysia.com/admin
```

## Database Storage

URL settings are stored in the `site_settings` table:

```sql
-- View current URL settings
SELECT setting_key, setting_value 
FROM site_settings 
WHERE setting_key LIKE '%url%' OR setting_key LIKE '%admin%';
```

## Integration

These URLs are used throughout the system:

- **Email notifications**: Uses default website URL for links
- **SEO metadata**: Uses default website URL for canonical URLs  
- **Admin redirects**: Uses admin login URL for security redirects
- **API responses**: Uses appropriate URL based on environment

---

## 🚀 Quick Setup

1. Navigate to **Admin Settings** → **URL Configuration**
2. Set your **Default Website URL** (production domain)
3. Configure **Custom Admin Path** for security
4. Set **Development URL** if using local development
5. Enable **Force HTTPS** for production
6. Save settings and test all URLs

Your HowToMalaysia website URLs are now properly configured! 🇲🇾