RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}  [L,R=301]
RewriteEngine On

# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.unithink\.co$ [NC]
RewriteRule ^(.*)$ https://unithink.co/$1 [L,R=301]

# Ensure existing files and directories load normally
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Remove .php extension from URLs (only if the corresponding .php file exists)
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^/.]+)/?$ $1.php [L]

# Rewrite Blog post URLs (only if it doesn't exist as a file or directory)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ blog-post.php?slug_url=$1 [QSA,L]

# Redirect truly non-existent pages to 404.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /404.php [L]

# Handle direct 404 errors
ErrorDocument 404 /404.php

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “alt-php74” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-alt-php74___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
