# Fixing Direct URL Access on cPanel (404 Errors)

## 🔴 Problem

When you access pages directly like:
- `https://yourdomain.com/verification`
- `https://yourdomain.com/check-eligibility`
- `https://yourdomain.com/about`

You get a **404 Error** or "Page Not Found"

BUT when you navigate through the app (starting from homepage), everything works fine.

## ✅ Solution

This is a common React Router issue. The server needs to redirect all requests to `index.html` so React Router can handle the routing.

---

## 🛠️ Fix Method 1: Using .htaccess (Apache Servers)

### Step 1: Check if .htaccess file exists

The build already includes `.htaccess` file. After uploading to cPanel:

1. Go to **cPanel File Manager**
2. Navigate to `public_html`
3. Click "Settings" in top right
4. Check "Show Hidden Files (dotfiles)"
5. Click "Save"
6. Look for `.htaccess` file

### Step 2: Create or Update .htaccess

If `.htaccess` doesn't exist or doesn't work, create/replace it with this content:

```apache
<IfModule mod_rewrite.c>
  # Enable Rewrite Engine
  RewriteEngine On
  RewriteBase /

  # Handle Frontend Routes - Send all requests to index.html
  # This allows React Router to handle all routes
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]
</IfModule>

# Prevent directory browsing
Options -Indexes

# Error Documents - Redirect all errors to index.html
ErrorDocument 404 /index.html
ErrorDocument 403 /index.html
ErrorDocument 500 /index.html
```

### Step 3: Save and Test

Save the file and test these URLs directly in browser:
- `https://yourdomain.com/verification`
- `https://yourdomain.com/check-eligibility`
- `https://yourdomain.com/contact-support`
- `https://yourdomain.com/signup`

All should work now! ✅

---

## 🛠️ Fix Method 2: If .htaccess Doesn't Work

Some shared hosting providers disable `.htaccess`. Try these alternatives:

### Option A: Enable mod_rewrite in cPanel

1. Go to cPanel
2. Look for "Apache Configuration" or "MultiPHP INI Editor"
3. Enable `mod_rewrite` if available
4. Restart Apache (if option available)

### Option B: Contact Hosting Support

Ask your hosting provider to:
1. Enable `mod_rewrite` for your domain
2. Allow `.htaccess` files
3. Set `AllowOverride All` for your directory

### Option C: Use web.config (for Windows/IIS servers)

If your server uses IIS instead of Apache, create `web.config`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
```

---

## 🧪 Testing After Fix

Test all these URLs by typing them directly in browser address bar:

### Public Pages
- ✅ `https://yourdomain.com/` (Home)
- ✅ `https://yourdomain.com/about`
- ✅ `https://yourdomain.com/how-it-works`
- ✅ `https://yourdomain.com/faqs`
- ✅ `https://yourdomain.com/testimonials`
- ✅ `https://yourdomain.com/check-eligibility`
- ✅ `https://yourdomain.com/contact-support`
- ✅ `https://yourdomain.com/login`

### Hidden Pages (Direct URL Only)
- ✅ `https://yourdomain.com/signup`
- ✅ `https://yourdomain.com/verification`

### After Login
- ✅ `https://yourdomain.com/dashboard`

All should load without 404 errors!

---

## 🔍 Troubleshooting

### Issue 1: Still Getting 404 Errors

**Check:**
1. Is `.htaccess` in the root (`public_html`) folder?
2. Can you see hidden files in File Manager?
3. Is the file named exactly `.htaccess` (with the dot)?
4. Did you save the file as "All Files" type (not .txt)?

**Fix:**
- Re-upload the `.htaccess` file
- Make sure it's in the same folder as `index.html`

### Issue 2: Internal Server Error (500)

**Problem:** .htaccess syntax error or mod_rewrite not enabled

**Fix:**
1. Contact hosting support to enable `mod_rewrite`
2. Use simplified .htaccess:
```apache
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
```

### Issue 3: Works Sometimes, Not Always

**Problem:** Browser caching old 404 page

**Fix:**
1. Clear browser cache (Ctrl+Shift+Delete)
2. Try in Incognito/Private mode
3. Hard refresh the page (Ctrl+F5)

### Issue 4: Homepage Works, Others Don't

**Problem:** .htaccess not being read

**Fix:**
1. Check file permissions: Set .htaccess to 644
2. Verify `AllowOverride` is enabled (ask hosting support)

---

## 📋 Quick Checklist

After deploying to cPanel:

- [ ] `.htaccess` file exists in `public_html`
- [ ] `.htaccess` is in the same folder as `index.html`
- [ ] Hidden files are visible in File Manager
- [ ] File permissions are correct (644 for .htaccess)
- [ ] Homepage loads: `https://yourdomain.com/`
- [ ] Direct URL works: `https://yourdomain.com/about`
- [ ] Direct URL works: `https://yourdomain.com/verification`
- [ ] Browser cache cleared
- [ ] Tested in incognito mode

---

## 📞 Still Not Working?

### Contact Your Hosting Provider

Send them this message:

> "Hi, I've deployed a React Single Page Application to my cPanel hosting. I need help enabling mod_rewrite and allowing .htaccess files so that direct URL access works correctly. Currently, pages like /verification and /about show 404 errors when accessed directly. Can you please enable mod_rewrite and set AllowOverride to All for my public_html directory?"

### Alternative: Use Hash Router (Last Resort)

If nothing works, you can modify the app to use hash routing (URLs will have # in them):
- `https://yourdomain.com/#/verification`
- `https://yourdomain.com/#/about`

Contact me if you need help implementing this.

---

## ✅ Success!

Once fixed, all pages will work when:
- Typing URL directly in address bar
- Refreshing the page (F5)
- Sharing links with others
- Bookmarking pages

**Your website will be fully functional! 🎉**
