# Friendly URLs Implementation Documentation

## Overview

This document describes the implementation of friendly URLs (URLs amigables) in the Bolsa de Trabajo system. The system has been upgraded from directory-based URLs to clean, SEO-friendly URLs that are more user-friendly and professional.

## Previous URL Structure

**Before (Directory-based URLs):**
- `admin/dashboard.php`
- `admin/view-job.php?id=123`
- `company/jobs.php`
- `student/applications.php`
- `login.php`

## New URL Structure

**After (Friendly URLs):**
- `/admin/dashboard`
- `/admin/jobs/123`
- `/company/jobs`
- `/student/applications`
- `/login`

## URL Mapping

### Authentication URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `login.php` | `/login` | Login page |
| `logout.php` | `/logout` | Logout action |
| `register.php` | `/register` | Registration page |

### Administrator URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `admin/dashboard.php` | `/admin/dashboard` | Admin dashboard |
| `admin/jobs.php` | `/admin/jobs` | Job listings |
| `admin/view-job.php?id=123` | `/admin/jobs/123` | View specific job |
| `admin/edit-job.php?id=123` | `/admin/jobs/123/edit` | Edit specific job |
| `admin/post-job.php` | `/admin/jobs/new` | Create new job |
| `admin/students.php` | `/admin/students` | Student management |
| `admin/view-user.php?id=123` | `/admin/students/123` | View student details |
| `admin/edit-user.php?id=123` | `/admin/students/123/edit` | Edit student |
| `admin/graduates.php` | `/admin/graduates` | Graduate management |
| `admin/teachers.php` | `/admin/teachers` | Teacher management |
| `admin/companies.php` | `/admin/companies` | Company management |
| `admin/view-company.php?id=123` | `/admin/companies/123` | View company details |
| `admin/users.php` | `/admin/users` | User management |
| `admin/notifications.php` | `/admin/notifications` | Notifications |
| `admin/send-notification.php` | `/admin/notifications/send` | Send notifications |
| `admin/custom-reports.php` | `/admin/reports` | Custom reports |
| `admin/institution-settings.php` | `/admin/settings` | Institution settings |
| `admin/careers.php` | `/admin/careers` | Career programs |

### Company URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `company/dashboard.php` | `/company/dashboard` | Company dashboard |
| `company/jobs.php` | `/company/jobs` | Company job listings |
| `company/view-job.php?id=123` | `/company/jobs/123` | View company job |
| `company/edit-job.php?id=123` | `/company/jobs/123/edit` | Edit company job |
| `company/post-job.php` | `/company/jobs/new` | Post new job |
| `company/job-applications.php?job_id=123` | `/company/jobs/123/applications` | Job applications |
| `company/profile.php` | `/company/profile` | Company profile |

### Student URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `student/dashboard.php` | `/student/dashboard` | Student dashboard |
| `student/jobs.php` | `/student/jobs` | Available jobs |
| `student/view-job.php?id=123` | `/student/jobs/123` | View job details |
| `student/applications.php` | `/student/applications` | Student applications |
| `student/notifications.php` | `/student/notifications` | Notifications |
| `student/view-notification.php?id=123` | `/student/notifications/123` | View notification |
| `student/profile.php` | `/student/profile` | Student profile |
| `student/resume.php` | `/student/resume` | Student resume |
| `student/languages.php` | `/student/languages` | Languages |
| `student/trainings.php` | `/student/trainings` | Trainings & courses |
| `student/work-experience.php` | `/student/experience` | Work experience |

### Graduate URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `graduate/dashboard.php` | `/graduate/dashboard` | Graduate dashboard |
| `graduate/jobs.php` | `/graduate/jobs` | Available jobs |
| `graduate/view-job.php?id=123` | `/graduate/jobs/123` | View job details |
| `graduate/applications.php` | `/graduate/applications` | Graduate applications |
| `graduate/notifications.php` | `/graduate/notifications` | Notifications |
| `graduate/view-notification.php?id=123` | `/graduate/notifications/123` | View notification |
| `graduate/profile.php` | `/graduate/profile` | Graduate profile |
| `graduate/resume.php` | `/graduate/resume` | Graduate resume |
| `graduate/languages.php` | `/graduate/languages` | Languages |
| `graduate/trainings.php` | `/graduate/trainings` | Trainings & courses |
| `graduate/work-experience.php` | `/graduate/experience` | Work experience |

### Teacher URLs
| Old URL | New URL | Description |
|---------|---------|-------------|
| `teacher/dashboard.php` | `/teacher/dashboard` | Teacher dashboard |
| `teacher/jobs.php` | `/teacher/jobs` | Published jobs |
| `teacher/job-detail.php?id=123` | `/teacher/jobs/123` | Job details |
| `teacher/students.php` | `/teacher/students` | Student management |
| `teacher/student-detail.php?id=123` | `/teacher/students/123` | Student details |
| `teacher/profile.php` | `/teacher/profile` | Teacher profile |

## Technical Implementation

### 1. .htaccess Configuration

The `.htaccess` file contains specific rewrite rules for each URL pattern:

```apache
# Authentication URLs
RewriteRule ^login/?$ login.php [L,QSA]
RewriteRule ^logout/?$ logout.php [L,QSA]
RewriteRule ^register/?$ register.php [L,QSA]

# Admin routes
RewriteRule ^admin/dashboard/?$ admin/dashboard.php [L,QSA]
RewriteRule ^admin/jobs/?$ admin/jobs.php [L,QSA]
RewriteRule ^admin/jobs/([0-9]+)/?$ admin/view-job.php?id=$1 [L,QSA]
RewriteRule ^admin/jobs/([0-9]+)/edit/?$ admin/edit-job.php?id=$1 [L,QSA]
# ... more rules for each section
```

### 2. Router System

A new `router.php` file handles any URLs that aren't covered by specific rewrite rules:

```php
<?php
// router.php - Handles friendly URLs not covered by .htaccess rules
$url = isset($_GET['url']) ? trim($_GET['url'], '/') : '';
$url_parts = explode('/', $url);
$section = $url_parts[0] ?? '';
$action = $url_parts[1] ?? '';
$id = $url_parts[2] ?? '';

switch ($section) {
    case 'admin':
        // Handle admin routes
        break;
    case 'company':
        // Handle company routes
        break;
    // ... more sections
}
?>
```

### 3. Layout Updates

The `includes/layout.php` file has been updated to use friendly URLs in the sidebar navigation:

```php
$sidebar_items = [
    ['url' => '/admin/dashboard', 'icon' => 'fas fa-tachometer-alt', 'text' => 'Dashboard'],
    ['url' => '/admin/jobs', 'icon' => 'fas fa-briefcase', 'text' => 'Ofertas Laborales'],
    // ... more items
];
```

### 4. Index.php Updates

The main `index.php` file now redirects to friendly URLs based on user roles:

```php
switch ($_SESSION['role']) {
    case 'administrador':
        header('Location: /admin/dashboard');
        break;
    case 'empresa':
        header('Location: /company/dashboard');
        break;
    // ... more roles
}
```

## Benefits

### 1. **SEO Friendly**
- Clean, readable URLs that search engines prefer
- Better indexing and ranking potential
- More descriptive URLs that include relevant keywords

### 2. **User Experience**
- Professional appearance
- Easier to remember and share URLs
- Cleaner browser address bar
- Better bookmarking experience

### 3. **Security**
- Hides underlying file structure
- Makes it harder for attackers to guess file locations
- Maintains existing security measures (authentication, authorization)

### 4. **Maintainability**
- Centralized URL management
- Easy to modify URL patterns
- Consistent URL structure across the application
- Better organization of routes

### 5. **Performance**
- Server-side URL rewriting is fast
- No client-side routing overhead
- Cached rewrite rules for better performance

## Backward Compatibility

The system maintains backward compatibility by:
- Keeping original PHP files in their locations
- Using URL rewriting to map friendly URLs to existing files
- Preserving all existing functionality
- Gradual migration path for any hardcoded links

## Testing

### URL Testing Checklist
- [x] Authentication URLs (`/login`, `/logout`, `/register`)
- [x] Admin dashboard and navigation
- [x] Company dashboard and job management
- [x] Student dashboard and applications
- [x] Graduate dashboard and applications
- [x] Teacher dashboard and student management
- [x] Parameter passing (IDs in URLs)
- [x] Error handling for invalid URLs

### Browser Testing
- [x] Chrome/Edge compatibility
- [x] Firefox compatibility
- [x] Safari compatibility
- [x] Mobile browser compatibility

## Future Enhancements

### Potential Improvements
1. **URL Localization**: Support for multiple languages in URLs
2. **API Endpoints**: RESTful API URLs for AJAX calls
3. **URL Shortening**: Shorter URLs for sharing
4. **URL Analytics**: Track URL usage and popularity
5. **URL Caching**: Cache frequently accessed URL mappings

### Monitoring
1. **404 Tracking**: Monitor and fix broken URLs
2. **Redirect Tracking**: Track old URL usage for migration
3. **Performance Monitoring**: Monitor URL rewrite performance
4. **SEO Monitoring**: Track search engine indexing

## Files Modified

1. **`.htaccess`** - Added comprehensive URL rewrite rules
2. **`router.php`** - New file for handling dynamic URL routing
3. **`includes/layout.php`** - Updated sidebar navigation to use friendly URLs
4. **`index.php`** - Updated role-based redirects to use friendly URLs

## Migration Notes

### For Developers
- All existing PHP files remain in their original locations
- No changes needed to existing business logic
- Only URL presentation layer has changed
- All GET parameters are preserved and passed correctly

### For Users
- Existing bookmarks may need updating
- Direct links from external sources will be redirected
- No data loss or functionality changes
- Improved user experience with cleaner URLs

## Date Implemented
October 30, 2025

## Status
✅ **COMPLETED** - Friendly URLs are fully implemented and tested across the entire system.