# MIM4U Domain Conflict Resolution

## Conflict Identified

**Issue**: `mim4u.org` exists as both:
1. **Root domain** in Cloudflare (Active, 2 visitors)
2. **Subdomain** of d-bis.org: `mim4u.org.d-bis.org` and `www.mim4u.org.d-bis.org`

## Current Configuration

### In d-bis.org DNS Zone:
```
mim4u.org.d-bis.org.     1  IN  CNAME  10ab22da-8ea3-4e2e-a896-27ece2211a05.cfargotunnel.com.
www.mim4u.org.d-bis.org.  1  IN  CNAME  10ab22da-8ea3-4e2e-a896-27ece2211a05.cfargotunnel.com.
```

### Separate Domain:
- `mim4u.org` (root domain) - Active in Cloudflare
- Status: Active, 2 visitors
- DNS records: Unknown (needs analysis)

## Impact

1. **User Confusion**: Users might try `mim4u.org` but services are at `mim4u.org.d-bis.org`
2. **SSL Certificates**: Different certificates needed for root vs subdomain
3. **Tunnel Configuration**: Root domain may need separate tunnel or redirect
4. **SEO/DNS**: Potential duplicate content issues

## Resolution Options

### Option 1: Use Root Domain (mim4u.org) as Primary ⭐ Recommended

**Action**:
1. Configure `mim4u.org` (root) to point to services
2. Redirect `mim4u.org.d-bis.org` → `mim4u.org`
3. Update tunnel configuration to use `mim4u.org` instead of `mim4u.org.d-bis.org`

**Pros**:
- Cleaner URLs (shorter)
- Better branding
- Standard practice

**Cons**:
- Requires DNS changes
- Need to update all references

### Option 2: Use Subdomain (mim4u.org.d-bis.org) as Primary

**Action**:
1. Keep `mim4u.org.d-bis.org` as primary
2. Redirect `mim4u.org` (root) → `mim4u.org.d-bis.org`
3. No changes to tunnel configuration

**Pros**:
- No tunnel changes needed
- Keeps d-bis.org structure

**Cons**:
- Longer URLs
- Less intuitive

### Option 3: Keep Both (Not Recommended)

**Action**:
1. Configure both independently
2. Point to same services
3. Maintain separate DNS records

**Pros**:
- Maximum flexibility

**Cons**:
- Duplicate maintenance
- Potential confusion
- SEO issues

## Recommended Solution: Option 1

### Step-by-Step Implementation

#### 1. Analyze Current mim4u.org Configuration

```bash
# Check DNS records for mim4u.org (root)
dig +short mim4u.org
dig +short www.mim4u.org
dig +short mim4u.org ANY

# Check if tunnel exists
# In Cloudflare Dashboard: Zero Trust → Networks → Tunnels
```

#### 2. Create/Update Tunnel for mim4u.org

If using root domain, create tunnel configuration:

```yaml
# /etc/cloudflared/tunnel-mim4u.yml
tunnel: <TUNNEL_ID_MIM4U>
credentials-file: /etc/cloudflared/credentials-mim4u.json

ingress:
  - hostname: mim4u.org
    service: http://192.168.11.21:80
    originRequest:
      httpHostHeader: mim4u.org
  
  - hostname: www.mim4u.org
    service: http://192.168.11.21:80
    originRequest:
      httpHostHeader: www.mim4u.org
  
  - service: http_status:404
```

#### 3. Update DNS Records

**In Cloudflare Dashboard for mim4u.org**:
- Create CNAME: `@` → `<tunnel-id>.cfargotunnel.com` (proxied)
- Create CNAME: `www` → `<tunnel-id>.cfargotunnel.com` (proxied)

**In Cloudflare Dashboard for d-bis.org**:
- Update `mim4u.org.d-bis.org` → Redirect to `https://mim4u.org`
- Update `www.mim4u.org.d-bis.org` → Redirect to `https://www.mim4u.org`

#### 4. Update Tunnel Configuration

Remove from shared tunnel (`10ab22da-8ea3-4e2e-a896-27ece2211a05`):
- Remove `mim4u.org.d-bis.org` entry
- Remove `www.mim4u.org.d-bis.org` entry

Add to new/separate tunnel for `mim4u.org` root domain.

#### 5. Update Application Configuration

Update any hardcoded references:
- Config files
- Environment variables
- Documentation
- SSL certificates

## Testing

After implementation:

```bash
# Test root domain
curl -I https://mim4u.org
curl -I https://www.mim4u.org

# Test subdomain redirect
curl -I https://mim4u.org.d-bis.org
# Should return 301/302 redirect to mim4u.org

# Verify SSL certificates
openssl s_client -connect mim4u.org:443 -servername mim4u.org < /dev/null
```

## Checklist

- [ ] Analyze current mim4u.org DNS records
- [ ] Decide on resolution option
- [ ] Create/update tunnel for mim4u.org (if using root)
- [ ] Update DNS records
- [ ] Update tunnel configurations
- [ ] Test accessibility
- [ ] Update documentation
- [ ] Update application configs
- [ ] Monitor for issues

## Summary

**Current State**: Conflicting configuration (root + subdomain)  
**Recommended**: Use `mim4u.org` (root) as primary, redirect subdomain  
**Priority**: Medium (not blocking but should be resolved)  
**Effort**: Low-Medium (requires DNS and tunnel updates)
