RewriteEngine On


# =========================================================
# CANONICAL DOMAIN + HTTPS
# =========================================================

RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\.mvskpowdercoating\.com$ [NC]
RewriteRule ^ https://www.mvskpowdercoating.com%{REQUEST_URI} [R=301,L]

# Products
RewriteRule ^products/?$ products.php [L,QSA]
RewriteRule ^products/([^/]+)/?$ product-category.php?slug=$1 [L,QSA]
RewriteRule ^products/([^/]+)/([^/]+)/?$ product.php?slug=$2 [L,QSA]

# Our Machines
RewriteRule ^machines/?$ machines.php [L,QSA]
RewriteRule ^machines/([^/]+)/?$ product.php?slug=$1 [L,QSA]

# Blogs
RewriteRule ^blog/?$ blog.php [L,QSA]
RewriteRule ^blog/([^/]+)/?$ blog-details.php?slug=$1 [L,QSA]


# About Sections
RewriteRule ^about/?$ about.php [L,QSA]
RewriteRule ^about/who-we-are/?$ about.php?section=who-we-are [L,QSA]
RewriteRule ^about/infrastructure/?$ about.php?section=infrastructure [L,QSA]
RewriteRule ^about/team/?$ about.php?section=team [L,QSA]

 
RewriteRule ^clients/?$ clients.php [L,QSA]
RewriteRule ^contact/?$ contact.php [L,QSA]
RewriteRule ^industries/?$ industries.php [L,QSA]

# Gallery

RewriteRule ^gallery/?$ gallery.php [L,QSA]
# Redirect old static .php URLs
RewriteCond %{THE_REQUEST} \s/+about\.php(?:[\s?]|$) [NC]
RewriteRule ^about\.php$ /about/ [R=301,L]

RewriteCond %{THE_REQUEST} \s/+clients\.php(?:[\s?]|$) [NC]
RewriteRule ^clients\.php$ /clients/ [R=301,L]

RewriteCond %{THE_REQUEST} \s/+contact\.php(?:[\s?]|$) [NC]
RewriteRule ^contact\.php$ /contact/ [R=301,L]

RewriteCond %{THE_REQUEST} \s/+industries\.php(?:[\s?]|$) [NC]
RewriteRule ^industries\.php$ /industries/ [R=301,L]

RewriteCond %{THE_REQUEST} \s/+blog\.php(?:[\s?]|$) [NC]
RewriteRule ^blog\.php$ /blog/ [R=301,L]

RewriteCond %{THE_REQUEST} \s/+products\.php(?:[\s?]|$) [NC]
RewriteRule ^products\.php$ /products/ [R=301,L]



# =========================================================
# GZIP COMPRESSION
# =========================================================

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/xml
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# =========================================================
# LOCATION PAGES
# =========================================================

# All locations listing
RewriteRule ^locations/?$ locations.php [L,QSA]

# Redirect old URL to new URL
# Old: /location/oil-skimmer/faridabad
# New: /faridabad/oil-skimmer
RewriteRule ^location/([^/]+)/([^/]+)/?$ /$2/$1 [R=301,L,NE]

# New URL: /faridabad/oil-skimmer
RewriteRule ^([^/]+)/([^/]+)/?$ location_detail.php?location=$1&product=$2 [L,QSA]
# =========================================================
# BROWSER CACHING
# =========================================================

<IfModule mod_expires.c>
    ExpiresActive On

    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/avif "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"

    ExpiresByType font/woff "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
    ExpiresByType application/font-woff "access plus 1 year"

    ExpiresByType text/css "access plus 1 month"

    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"

    ExpiresByType application/pdf "access plus 1 month"
</IfModule>

# =========================================================
# CACHE CONTROL
# =========================================================

<IfModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|webp|avif|svg|woff|woff2)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>

    <FilesMatch "\.(css|js)$">
        Header set Cache-Control "public, max-age=2592000"
    </FilesMatch>
</IfModule>

# =========================================================
# SECURITY HEADERS
# =========================================================

<IfModule mod_headers.c>
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"
</IfModule>

# =========================================================
# DIRECTORY PROTECTION
# =========================================================

Options -Indexes

# =========================================================
# BLOCK ACCESS TO SENSITIVE FILES
# =========================================================

<FilesMatch "^(\.env|\.git|composer\.(json|lock)|package(-lock)?\.json)$">
    Require all denied
</FilesMatch>

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