.htaccess automatically delete itself

Website URL

https://designprocess.great-site.net/

Error Message

N/A

Other Information

I just want my OG image to show up on Social Media I tried everything also whenever I try to create htacess it deletes itself and yes I put it inside my htdoc folder

.htaccess (3 KB)

# Enable RewriteEngine
RewriteEngine On

# ----------------------------
# URL Rewriting
# ----------------------------

# Remove trailing slash (except for directories)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Remove .php extension from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ /$1.php [L]

# Remove .html extension from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.html -f
RewriteRule ^(.*)$ /$1.html [L]

# Redirect .php and .html URLs to extensionless versions
RewriteCond %{THE_REQUEST} \s/([^/?]+)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/([^/?]+)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]

# ----------------------------
# Open Graph (OG) Configuration
# ----------------------------

# Ensure robots.txt is accessible
<Files "robots.txt">
    Order Allow,Deny
    Allow from all
</Files>

# Enable CORS for images (allow OG crawlers to access images)
<IfModule mod_headers.c>
  Header set Access-Control-Allow-Origin "*"
</IfModule>

# Set MIME types for images to ensure they are properly served
AddType image/jpg .jpg
AddType image/jpeg .jpeg
AddType image/png .png
AddType image/gif .gif

# ----------------------------
# Caching Rules for Better Performance
# ----------------------------

<IfModule mod_expires.c>
  ExpiresActive On

  # HTML files - cache for 0 seconds (dynamic content)
  ExpiresByType text/html "access plus 0 seconds"

  # CSS and JavaScript - cache for 0 seconds (always revalidate)
  ExpiresByType text/css "access plus 0 seconds"
  ExpiresByType application/javascript "access plus 0 seconds"
  ExpiresByType application/x-javascript "access plus 0 seconds"

  # Images - cache for 1 month
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"

  # Fonts - cache for 1 year (no changes)
  ExpiresByType application/font-woff "access plus 1 year"
  ExpiresByType application/font-woff2 "access plus 1 year"

  # PDF files - cache for 1 month (no changes)
  ExpiresByType application/pdf "access plus 1 month"

  # Video and audio - cache for 1 month
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType audio/mpeg "access plus 1 month"
</IfModule>

# ----------------------------
# Remove ?i=1
# ----------------------------
RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

# Optional: Redirect www to non-www (or vice versa)
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Optional: Force HTTPS (uncomment to enable)
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Handle 404 errors gracefully (optional)
ErrorDocument 404 /404.html

robots.txt

# Block all crawlers from the "sections" folder
User-agent: *
Disallow: /sections/

# Allow Facebook's crawler
User-agent: facebookexternalhit
Disallow:

# Allow Twitter's crawler
User-agent: Twitterbot
Disallow:

# Allow LinkedIn's crawler
User-agent: LinkedInBot
Disallow:

robot.txt (288 Bytes)

Note that your code to remove the i GET parameter will result in users that fail the challenge to just see an endless redirect instead of the help page. That will also cause quite a few additional hits to your website if they retry the action and continue to fail the challenge.

Also, your OG image won’t be able to be visible on social media because of the security system:

6 Likes

Aww is there really no other way for crawlers to fetch the og details and files without resorting to premium? Having a good Og preview pic somehow gives potential client trust boost visiting the website. Not that I don’t want to resort to premium, I just don’t have the money yet.

Web crawlers can (Google, Bing, etc), but most social media platforms cannot (Discord, Twitter, etc) as they get blocked by the security system.

5 Likes

I see, that explains why I can debug the og image using social preview share plugin from chrome but still don’t show up on apps like facebook. welp thanks Greenreader9, for the clarification and fast response.