.htaccess जनरेटर

टकराव जाँच के साथ Apache .htaccess रीडायरेक्ट, कैश और सुरक्षा नियम बनाएँ

विकल्प

कैनोनिकल URL
कैनोनिकल होस्ट
अंतिम स्लैश

/blog/index.html को /blog/ पर भेजा जाता है।

कस्टम रीडायरेक्ट
रीडायरेक्ट: 0

अभी कोई कस्टम रीडायरेक्ट नहीं है। एक जोड़ें या एक साथ पेस्ट का उपयोग करें।

बनाई गई .htaccess

# Generated by the CodingTool.dev .htaccess Generator for Apache 2.4.
# Needs AllowOverride AuthConfig FileInfo Indexes Options (or All); Apache answers 500 for directives it does not allow.
# Place this file in the document root. Test on a staging site before going live.

# Disable directory listings.
Options -Indexes

# Deny access to .htaccess, .htpasswd and other .ht files.
<FilesMatch "^\.ht">
  Require all denied
</FilesMatch>

# Deny backup, dump and editor swap files such as .bak, .old, .sql, .swp and ~ copies.
<FilesMatch "(\.(bak|old|sql|swp)|~)$">
  Require all denied
</FilesMatch>

<IfModule mod_rewrite.c>
  RewriteEngine On

  # Block dotfiles and dot-folders such as .env and .git; keep /.well-known/ reachable.
  RewriteCond %{REQUEST_URI} !(^|/)\.well-known/
  RewriteRule (^|/)\. - [F]

  # Force HTTPS: redirect every HTTP request to the same host over HTTPS.
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

<IfModule mod_headers.c>
  # Basic security headers. Adjust Permissions-Policy if your site uses these features.
  Header always set X-Content-Type-Options "nosniff"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"
  Header always set X-Frame-Options "SAMEORIGIN"
  Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
</IfModule>

# Compress text responses. AddOutputFilterByType needs mod_filter in Apache 2.4.
<IfModule mod_deflate.c>
  <IfModule mod_filter.c>
    # Text and markup
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
    # Scripts and data
    AddOutputFilterByType DEFLATE text/javascript application/javascript application/json application/ld+json application/manifest+json
    # Feeds and XML
    AddOutputFilterByType DEFLATE application/xml application/rss+xml application/atom+xml
    # SVG and uncompressed fonts
    AddOutputFilterByType DEFLATE image/svg+xml font/ttf font/otf application/vnd.ms-fontobject
  </IfModule>
</IfModule>

# Browser caching (conservative): short lifetimes that are safe without versioned file names.
<IfModule mod_expires.c>
  ExpiresActive On
  # HTML and data: always revalidate
  ExpiresByType text/html "access plus 0 seconds"
  ExpiresByType application/json "access plus 0 seconds"
  ExpiresByType application/ld+json "access plus 0 seconds"
  ExpiresByType application/xml "access plus 0 seconds"
  ExpiresByType text/xml "access plus 0 seconds"
  # Feeds
  ExpiresByType application/rss+xml "access plus 1 hour"
  ExpiresByType application/atom+xml "access plus 1 hour"
  # CSS and JavaScript
  ExpiresByType text/css "access plus 1 week"
  ExpiresByType text/javascript "access plus 1 week"
  ExpiresByType application/javascript "access plus 1 week"
  # Web app manifest
  ExpiresByType application/manifest+json "access plus 1 week"
  # Images
  ExpiresByType image/avif "access plus 1 month"
  ExpiresByType image/gif "access plus 1 month"
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType image/png "access plus 1 month"
  ExpiresByType image/svg+xml "access plus 1 month"
  ExpiresByType image/webp "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 month"
  # Fonts
  ExpiresByType font/woff "access plus 1 month"
  ExpiresByType font/woff2 "access plus 1 month"
  ExpiresByType font/ttf "access plus 1 month"
  ExpiresByType font/otf "access plus 1 month"
  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  # Audio and video
  ExpiresByType audio/mpeg "access plus 1 month"
  ExpiresByType audio/ogg "access plus 1 month"
  ExpiresByType video/mp4 "access plus 1 month"
  ExpiresByType video/webm "access plus 1 month"
</IfModule>

.htaccess तभी काम करती है जब Apache की AllowOverride सेटिंग इन निर्देशों की अनुमति देती है।

ब्राउज़र नाम की शुरुआत का बिंदु हटा देते हैं, इसलिए फ़ाइल htaccess.txt नाम से सेव होती है। सर्वर पर इसका नाम .htaccess कर दें।

निष्कर्ष

कोई टकराव नहीं मिला
त्रुटियाँ: 0 · चेतावनियाँ: 0 · रीडायरेक्ट: 0

नोट (3)

  • नोट: TLS समाप्त करने वाले लोड बैलेंसर या CDN के पीछे %{HTTPS} off रहता है और HTTPS नियम लूप में जा सकता है। पहले अपने होस्ट से पूछें।

  • नोट: AllowOverride AuthConfig, FileInfo, Indexes, Options (या All) चाहिए। अनुमति से बाहर का कोई निर्देश होने पर Apache 500 लौटाता है।

  • नोट: mod_rewrite, mod_headers, mod_deflate, mod_filter, mod_expires लोड न होने पर उसके ब्लॉक चुपचाप छोड़ दिए जाते हैं।

इस फ़ाइल में

  • सर्वर विकल्प
  • फ़ाइल सुरक्षा
  • रीराइट नियम
  • रिस्पॉन्स हेडर
  • कम्प्रेशन
  • ब्राउज़र कैश

त्रुटियाँ: 0 · चेतावनियाँ: 0 · रीडायरेक्ट: 0

यह क्या बनाता है

यह जनरेटर आम रीडायरेक्ट, परफ़ॉर्मेंस और सुरक्षा ज़रूरतों के लिए Apache 2.4 की .htaccess फ़ाइल लिखता है: HTTPS ज़रूरी करना, एक कैनोनिकल होस्ट, अंतिम स्लैश और index.html की सफ़ाई, कस्टम 301/302/307/308 रीडायरेक्ट, gzip कम्प्रेशन, Expires कैश प्रीसेट, फ़ोल्डर सूची और डॉट फ़ाइलों की सुरक्षा, बुनियादी सुरक्षा हेडर, वैकल्पिक HSTS और कस्टम एरर पेज। हर हिस्से में टिप्पणी होती है और क्रम हमेशा एक जैसा रहता है, ताकि बदलाव आसानी से पढ़े जा सकें।

टकराव की जाँच

हर रीडायरेक्ट लिखने से पहले जाँचा जाता है: गलत स्रोत, असुरक्षित या अनपेक्षित गंतव्य प्रोटोकॉल, डुप्लिकेट, खुद पर रीडायरेक्ट, A से B और फिर A पर लौटने वाले लूप, और एक अतिरिक्त कदम जोड़ने वाली चेन। लूप बनाने वाले या कभी न चलने वाले नियम फ़ाइल से बाहर रहते हैं और नतीजों में दिखते हैं। कैनोनिकल होस्ट और अंतिम स्लैश एक ही विकल्प चुनने वाले हैं, इसलिए www जोड़ें और www हटाएँ जैसे विरोधी नियम एक साथ नहीं चल सकते।

Apache की ज़रूरी बारीकियाँ

सभी रीराइट नियम एक ही IfModule mod_rewrite ब्लॉक में रहते हैं, जिसमें RewriteEngine On सिर्फ़ एक बार आता है। HTTPS और होस्ट का बदलाव एक ही रीडायरेक्ट में होता है, अंतिम स्लैश वाले नियम असली फ़ाइलों और फ़ोल्डरों को छोड़ देते हैं, और स्लैश व index रीडायरेक्ट सिर्फ़ GET और HEAD अनुरोधों पर लागू होते हैं। एक्सेस कंट्रोल के लिए Require all denied इस्तेमाल होता है, पुराना Order और Deny सिंटैक्स कभी नहीं। मॉड्यूल पर निर्भर ब्लॉक IfModule में लिपटे रहते हैं, इसलिए मॉड्यूल न होने पर साइट नहीं टूटती, सिर्फ़ वह ब्लॉक छूट जाता है।

डिप्लॉय करने से पहले

.htaccess तभी काम करती है जब सर्वर की AllowOverride सेटिंग इन निर्देशों की अनुमति दे; वरना Apache 500 लौटाता है। फ़ाइल को डॉक्यूमेंट रूट में रखें, क्योंकि कस्टम रीडायरेक्ट के पाथ उसी के सापेक्ष होते हैं। TLS समाप्त करने वाले प्रॉक्सी या CDN के पीछे HTTPS नियम असली स्कीम नहीं देख पाता और लूप में जा सकता है। HSTS तभी चालू करें जब HTTPS हर जगह चल रहा हो, और छोटे max-age से शुरू करें। ब्राउज़र डाउनलोड को htaccess.txt नाम से सेव करते हैं; सर्वर पर इसका नाम .htaccess कर दें। सब कुछ आपके ब्राउज़र में चलता है और कुछ भी अपलोड नहीं होता।

CodingTool अब आधिकारिक तौर पर उपलब्ध है

Launched on StartupBaseCodingTool.dev - Free, Fast & Easy Developer Tools in One Place | Product HuntCodingTool - Featured on Startup FameFazier badgeListed on Turbo0Featured on Twelve ToolsFeatured on Findly.toolsLaunchpadly Startup DirectoryCodingTool.dev — Featured on Smol Launch