RewriteEngine On



# Redirect requests without extension to .php files
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)$ $1.php [L]




# Set the base directory
# If your project is in a subfolder like "my-blog", change this to "/"
RewriteBase /

# Deny access to sensitive files
<Files ".htaccess">
    Require all denied
</Files>
<Files "dbconnection.php">
    Require all denied
</Files>

# Rewrite rule for the blog listing page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/?$ blog.php [L,QSA]

# Rewrite rule for a single post page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([a-zA-Z0-9-]+)/?$ post.php?slug=$1 [L,QSA]


# Rewrite rule for 404 page not found
ErrorDocument 404 /404.php


