# ---------------------------------------------------------
# Enable Rewrite Engine
# ---------------------------------------------------------
RewriteEngine On

# ---------------------------------------------------------
# ENV → Detect Localhost
# ---------------------------------------------------------
RewriteCond %{HTTP_HOST} ^(localhost|127\.0\.0\.1)$ [NC]
RewriteRule ^ - [E=IS_LOCAL:1]

# ---------------------------------------------------------
# 1) Force HTTPS + WWW (ALL pages) - put FIRST
# ---------------------------------------------------------
RewriteCond %{ENV:IS_LOCAL} !1
RewriteCond %{HTTP_HOST} !^www\.risewebmedia\.com$ [NC,OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.risewebmedia.com%{REQUEST_URI} [R=301,L]

# ---------------------------------------------------------
# 2) Redirect /index and /index.php to homepage
# ---------------------------------------------------------
RewriteRule ^index(\.php)?$ https://www.risewebmedia.com/ [L,R=301]

# ---------------------------------------------------------
# 3) Service Redirects
# ---------------------------------------------------------
RewriteRule ^affiliate-marketing/?$ https://www.risewebmedia.com/affiliate-marketing-solution [L,R=301]
RewriteRule ^content-marketing/?$ https://www.risewebmedia.com/content-marketing-solution [L,R=301]
RewriteRule ^seo/?$ https://www.risewebmedia.com/seo-service [L,R=301]
RewriteRule ^ppc/?$ https://www.risewebmedia.com/google-ads-management [L,R=301]
RewriteRule ^one-year/?$ https://www.risewebmedia.com/one-year-domain-hosting-services-solutions [L,R=301]
RewriteRule ^marketing-analytics/?$ https://www.risewebmedia.com/marketing-analytics-service [L,R=301]
RewriteRule ^multiple-currency/?$ https://www.risewebmedia.com/multiple-currency-integration [L,R=301]
RewriteRule ^smm/?$ https://www.risewebmedia.com/social-media-marketing [L,R=301]
RewriteRule ^unlimited/?$ https://www.risewebmedia.com/unlimited-web-design [L,R=301]
RewriteRule ^email-marketing/?$ https://www.risewebmedia.com/email-marketing-solution [L,R=301]
RewriteRule ^mobile-marketing/?$ https://www.risewebmedia.com/mobile-marketing-solution [L,R=301]
RewriteRule ^android-apps/?$ https://www.risewebmedia.com/android-app-development-solution [L,R=301]
RewriteRule ^ios-app/?$ https://www.risewebmedia.com/ios-app-development-solution [L,R=301]
RewriteRule ^single-currency/?$ https://www.risewebmedia.com/single-currency-payment-integration [L,R=301]
RewriteRule ^logo-design/?$ https://www.risewebmedia.com/logo-design-service [L,R=301]
RewriteRule ^pdf-brochure-design/?$ https://www.risewebmedia.com/pdf-brochure-design-service [L,R=301]
RewriteRule ^mobile-responsive/?$ https://www.risewebmedia.com/mobile-responsive-website [L,R=301]
RewriteRule ^e-store-like-amazon/?$ https://www.risewebmedia.com/build-e-store-like-amazon [L,R=301]
RewriteRule ^crm-sales/?$ https://www.risewebmedia.com/crm-based-solutions [L,R=301]
RewriteRule ^erp-sales/?$ https://www.risewebmedia.com/erp-software-solution [L,R=301]
RewriteRule ^about/?$ https://www.risewebmedia.com/about-us [L,R=301]
RewriteRule ^single-page/?$ https://www.risewebmedia.com/single-page-website [L,R=301]
RewriteRule ^three-pages/?$ https://www.risewebmedia.com/three-pages-website [L,R=301]
RewriteRule ^five-pages/?$ https://www.risewebmedia.com/five-pages-website [L,R=301]

# ---------------------------------------------------------
# 4) Remove .php extension from URLs (EXCEPT send.php)
# ---------------------------------------------------------
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteCond %1 !^send$ [NC]
RewriteRule ^ %1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/]+)$ $1.php [L]

# ---------------------------------------------------------
# 5) Security Headers
# ---------------------------------------------------------
<IfModule mod_headers.c>
Header always set X-Frame-Options "SAMEORIGIN"
Header always set X-XSS-Protection "1; mode=block"
Header always set X-Content-Type-Options "nosniff"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
</IfModule>

# ---------------------------------------------------------
# 6) Disable directory browsing
# ---------------------------------------------------------
Options -Indexes

# ---------------------------------------------------------
# 7) Cache static files
# ---------------------------------------------------------
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/* "access plus 3 months"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 3 months"
    ExpiresByType video/* "access plus 6 months"
</IfModule>

Redirect 301 /3-page-site.php https://www.risewebmedia.com/three-pages-website
Redirect 301 /5-page-site.php https://www.risewebmedia.com/five-pages-website
