# TESTE TEMP - deny total wp-login
<Files "wp-login.php">
    Require all denied
</Files>

# TEMP EMERGÊNCIA - wp-login apenas IPs autorizados
<Files "wp-login.php">
    <RequireAny>
        Require ip 176.223.24.198
        Require ip 83.223.227.210
        Require ip 37.189.140.219
        Require ip 85.138.236.245
    </RequireAny>
</Files>

# BLOQUEIO XML-RPC - antes de WordPress/WP Rocket
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^xmlrpc\.php$ - [F,L]
</IfModule>

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (MJ12bot|PetalBot|Bytespider|AhrefsBot|SemrushBot) [NC]
RewriteRule .* - [F,L]
</IfModule>

# BEGIN WP Rocket
# Use UTF-8 encoding for anything served text/plain or text/html
AddDefaultCharset UTF-8
# Force UTF-8 for a number of file formats
<IfModule mod_mime.c>
AddCharset UTF-8 .atom .css .js .json .rss .vtt .xml
</IfModule>

# FileETag None is not enough for every server.
<IfModule mod_headers.c>
Header unset ETag
</IfModule>

# Since we’re sending far-future expires, we don’t need ETags for static content.
# developer.yahoo.com/performance/rules.html#etags
FileETag None

<IfModule mod_alias.c>
<FilesMatch "\.(html|htm|rtf|rtx|txt|xsd|xsl|xml)$">
<IfModule mod_headers.c>
Header set X-Powered-By "WP Rocket/3.21.2"
Header unset Pragma
Header append Cache-Control "public"
Header unset Last-Modified
</IfModule>
</FilesMatch>

<FilesMatch "\.(css|htc|js|asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip)$">
<IfModule mod_headers.c>
Header unset Pragma
Header append Cache-Control "public"
</IfModule>
</FilesMatch>
</IfModule>

<IfModule mod_mime.c>
	AddType image/avif                                  avif
    AddType image/avif-sequence                         avifs
</IfModule>
# Expires headers (for better cache control)
<IfModule mod_expires.c>
	ExpiresActive on
	ExpiresDefault                              "access plus 1 month"
	# cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
	ExpiresByType text/cache-manifest           "access plus 0 seconds"
	# Your document html
	ExpiresByType text/html                     "access plus 0 seconds"
	# Data
	ExpiresByType text/xml                      "access plus 0 seconds"
	ExpiresByType application/xml               "access plus 0 seconds"
	ExpiresByType application/json              "access plus 0 seconds"
	# Feed
	ExpiresByType application/rss+xml           "access plus 1 hour"
	ExpiresByType application/atom+xml          "access plus 1 hour"
	# Favicon (cannot be renamed)
	ExpiresByType image/x-icon                  "access plus 1 week"
	# Media: images, video, audio
	ExpiresByType image/gif                     "access plus 4 months"
	ExpiresByType image/png                     "access plus 4 months"
	ExpiresByType image/jpeg                    "access plus 4 months"
	ExpiresByType image/webp                    "access plus 4 months"
	ExpiresByType video/ogg                     "access plus 4 months"
	ExpiresByType audio/ogg                     "access plus 4 months"
	ExpiresByType video/mp4                     "access plus 4 months"
	ExpiresByType video/webm                    "access plus 4 months"
	ExpiresByType image/avif                    "access plus 4 months"
	ExpiresByType image/avif-sequence           "access plus 4 months"
	# HTC files  (css3pie)
	ExpiresByType text/x-component              "access plus 1 month"
	# Webfonts
	ExpiresByType font/ttf                      "access plus 4 months"
	ExpiresByType font/otf                      "access plus 4 months"
	ExpiresByType font/woff                     "access plus 4 months"
	ExpiresByType font/woff2                    "access plus 4 months"
	ExpiresByType image/svg+xml                 "access plus 4 months"
	ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
	# CSS and JavaScript
	ExpiresByType text/css                      "access plus 1 year"
	ExpiresByType text/javascript               "access plus 1 year"
	ExpiresByType application/javascript        "access plus 1 year"
</IfModule>
# Gzip compression
<IfModule mod_deflate.c>
# Active compression
SetOutputFilter DEFLATE
# Force deflate for mangled headers
<IfModule mod_setenvif.c>
<IfModule mod_headers.c>
SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
# Don’t compress images and other uncompressible content
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|rar|zip|exe|flv|mov|wma|mp3|avi|swf|mp?g|mp4|webm|webp|pdf)$ no-gzip dont-vary
</IfModule>
</IfModule>

# Compress all output labeled with one of the following MIME-types
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE application/atom+xml \
		                          application/javascript \
		                          application/json \
		                          application/rss+xml \
		                          application/vnd.ms-fontobject \
		                          application/x-font-ttf \
		                          application/xhtml+xml \
		                          application/xml \
		                          font/opentype \
		                          image/svg+xml \
		                          image/x-icon \
		                          text/css \
		                          text/javascript \
		                          text/html \
		                          text/plain \
		                          text/x-component \
		                          text/xml
</IfModule>
<IfModule mod_headers.c>
Header append Vary: Accept-Encoding
</IfModule>
</IfModule>


# END WP Rocket

# BLOQUEIO XML-RPC - proteção contra ataques
<Files "xmlrpc.php">
Require all denied
</Files>

RewriteOptions inherit


<IfModule mod_rewrite.c>
# RewriteEngine On

# RewriteCond %{REQUEST_URI} ^/wp-plain\.php$ [NC,OR]
# RewriteCond %{REQUEST_URI} ^/ALFA_DATA/alfacgiapi/perl\.alfa$ [NC,OR]
# RewriteCond %{REQUEST_URI} ^/alfacgiapi/perl\.alfa$ [NC]
# RewriteRule .* - [F,L]

# RewriteCond %{REQUEST_URI} ^/(wp-png\.php|jp\.php|tfm\.php|admin-footer\.php) [NC]
# RewriteRule .* - [F,L]

# RewriteCond %{REQUEST_URI} ^/xmlrpc\.php [NC]
# RewriteRule .* - [F,L]

# RewriteCond %{QUERY_STRING} (eval\(|base64_encode|union.*select|script) [NC]
# RewriteRule .* - [F,L]

# RewriteCond %{REQUEST_URI} ^/wp-admin/admin-ajax\.php [NC]
# RewriteCond %{HTTP_REFERER} !motorpor\.pt [NC]
# RewriteRule .* - [F,L]

# RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR]
# RewriteCond %{REMOTE_ADDR} ^116\.179\. [OR]
# RewriteCond %{REMOTE_ADDR} ^220\.181\.
# RewriteRule .* - [F,L]

# RewriteCond %{REQUEST_URI} ^/wp-json [NC]
# RewriteCond %{HTTP_USER_AGENT} !(Mozilla|Chrome|Safari|Firefox) [NC]
# RewriteRule .* - [F,L]

</IfModule>

# BEGIN Motorpor deleted vehicle redirects
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^carros/citroen\-e\-berlingo\-vc\-3/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/mercedes\-classe\-a\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/kia\-xceed\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-captur\-10/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-sandero\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-3008\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-duster\-8/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/opel\-crossland/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-captur\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-308\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-208\-20/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-duster\-7/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/opel\-corsa\-14/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-208\-13/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-11/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/kia\-stonic\-8/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/nissan\-micra/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-500e\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-clio\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-500\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/mitsubishi\-space\-star/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-r5\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-symbioz\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-jogger\-6/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-500\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/volkswagen\-t\-cross/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/jeep\-avenger\-19/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/nissan\-juke\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-31/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-duster\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/jeep\-avenger\-10/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/bmw\-x1/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-clio/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/volkswagen\-t\-roc\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/volkswagen\-t\-roc\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/volkswagen\-t\-roc\-3/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/jeep\-avenger\-12/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/ds\-automobiles\-ds\-7/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/opel\-corsa\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/kia\-stonic\-7/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/kia\-xceed\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-500/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-208/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-spring\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-29/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-jogger\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-43/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/ford\-courier/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-15/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-600\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-e\-2008\-8/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-captur\-11/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/renault\-megane\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/citroen\-c3\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-600\-7/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/kia\-rio/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-tipo\-6/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-2008\-30/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-duster\-2/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/dacia\-sandero\-3/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/citroen\-e\-c3\-3/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/fiat\-panda\-7/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-5008\-4/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/opel\-frontera/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
RewriteRule ^carros/peugeot\-3008\-5/?$ https://apv.motorpor.pt/usados/ [R=301,L,NE]
</IfModule>
# END Motorpor deleted vehicle redirects

# BEGIN WordPress
# Les directives (lignes) entre « BEGIN WordPress » et « END WordPress » sont générées
# dynamiquement, et doivent être modifiées uniquement via les filtres WordPress.
# Toute modification des directives situées entre ces marqueurs sera surchargée.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

# BEGIN GZIP COMPRESSION
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
# END GZIP COMPRESSION

# BEGIN DEFLATE COMPRESSION
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" "application/javascript" "application/json" "application/ld+json" "application/manifest+json" "application/rdf+xml" "application/rss+xml" "application/schema+json" "application/vnd.geo+json" "application/vnd.ms-fontobject" "application/x-font-ttf" "application/x-javascript" "application/x-web-app-manifest+json" "application/xhtml+xml" "application/xml" "font/eot" "font/opentype" "image/bmp" "image/svg+xml" "image/vnd.microsoft.icon" "image/x-icon" "text/cache-manifest" "text/css" "text/html" "text/javascript" "text/plain" "text/vcard" "text/vnd.rim.location.xloc" "text/vtt" "text/x-component" "text/x-cross-domain-policy" "text/xml"
</IfModule>
# END DEFLATE COMPRESSION

# cPanel PHP config (mantido intacto)
<IfModule php8_module>
php_flag display_errors Off
php_value max_execution_time 600
php_value max_input_time 600
php_value max_input_vars 5000
php_value memory_limit 1024M
php_value post_max_size 256M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
php_value upload_max_filesize 128M
php_flag zlib.output_compression Off
php_value date.timezone "Europe/Lisbon"
</IfModule>

<IfModule lsapi_module>
php_flag display_errors Off
php_value max_execution_time 600
php_value max_input_time 600
php_value max_input_vars 5000
php_value memory_limit 1024M
php_value post_max_size 256M
php_value session.gc_maxlifetime 1440
php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
php_value upload_max_filesize 128M
php_flag zlib.output_compression Off
php_value date.timezone "Europe/Lisbon"
</IfModule>

<IfModule mime_module>
AddHandler application/x-httpd-ea-php82 .php .php8 .phtml
</IfModule>

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php8_module>
   php_flag display_errors Off
   php_value max_execution_time 600
   php_value max_input_time 600
   php_value max_input_vars 10000
   php_value memory_limit 1024M
   php_value post_max_size 256M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
   php_value upload_max_filesize 128M
   php_flag zlib.output_compression Off
   php_value date.timezone "Europe/Lisbon"
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 600
   php_value max_input_time 600
   php_value max_input_vars 10000
   php_value memory_limit 1024M
   php_value post_max_size 256M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php82"
   php_value upload_max_filesize 128M
   php_flag zlib.output_compression Off
   php_value date.timezone "Europe/Lisbon"
</IfModule>
# END cPanel-generated php ini directives, do not edit

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