<IfModule mod_rewrite.c>
ErrorDocument 404 /error.php
RewriteEngine on

# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Prevent direct access to .php files
RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule ^ - [F]

# Rewrite clean URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]

# Redirect direct access to error.php
RewriteCond %{THE_REQUEST} \s/error\.php\s [NC]
RewriteRule ^ - [F]

# Rewrite URL for blog dengan judul SEO-friendly
RewriteRule ^blog-(.*)$ blog.php?judul=$1 [L,QSA]
RewriteRule ^page-(.*)$ page.php?judul=$1 [L,QSA]
RewriteRule ^verifikasi-(.*)$ verifikasi.php?token=$1 [L,QSA]
RewriteRule ^detail-freelance-(.*)$ detail-freelance.php?name=$1 [L,QSA]
RewriteRule ^detail-project-(.*)$ detail-project.php?judul=$1 [L,QSA]
RewriteRule ^detail-service-(.*)$ detail-service.php?judul=$1 [L,QSA]
RewriteRule ^bid-project-(.*)$ bid-project.php?judul=$1 [L,QSA]

# Redirect direct access to other .php files to error.php
RewriteCond %{THE_REQUEST} \.php\s [NC]
RewriteRule ^(.*)$ error.php [L]

</IfModule>
