Generador online de .htaccess

Actualizado el miércoles, 26 junio, 2019

Generador online de .htaccess (htaccess online generator).

Revisando los repositorios de Github, encontré un generador online de .htaccess que quiero compartir con los lectores de «Sololinux«.

Al ver el código, me sorprendió el buen diseño y trabajo que el amigo Emirodgar había realizado.

El resultado final está muy elaborado, y cuenta con excelentes características, que pasamos a enumerar:

Opciones de acceso

  • Establece el dominio principal.
  • Redireccionamiento a www.
  • https redirect.

Opciones de configuración

  • Página de acceso predeterminada.
  • Juego de caracteres predeterminado.
  • Forzar la descarga de un tipo de archivo.
  • Limitar el tamaño del archivo a subir.
  • Configurar el correo del administrador.

Actuación

  • Activar la compresión Gzip.
  • Habilitar los encabezados de Keep-Alive.
  • Vencimiento de los encabezados (headers).

Páginas de error personalizadas

  • Error 404
  • Error 500

Opciones de seguridad

  • Bloquear la navegación por el directorio.
  • Deshabilitar la ejecución de CGI.
  • Oculta la información sensible del servidor.
  • Evitar que inserten tus páginas en otros sitios web.
  • Deshabilita la firma del servidor.
  • Bloquea los robots de SPAM más conocidos.
  • Evita el acceso ilegal o inseguro.
  • No permitir la ejecución de scripts (define las extensiones).
  • Deniega los métodos de solicitud que definas.
  • No permite el hotlinking.

Antes de realizar cualquier modificación en tu archivo htaccess, te recomiendo que hagas una copia de seguridad. Es algo típico que por cualquier error en el archivo, el servidor lance un error 500.

Generador online de .htaccess 1

 

Generador online de .htaccess

Como considero que es una utilidad altamente recomendable, la hemos subido a sololinux, para que puedas generar tu archivo htaccess, lo encontraras en la siguiente url.

Si prefieres tener tu propio generador online de .htaccess, es tan simple como crear un archivo html y copiar y pegar lo siguiente.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Free .htaccess Online Generator</title>

    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">

    <style>
      body {
        padding-top: 2rem;
        padding-bottom: 2rem;
      }
      h3 {
        margin-top: 2rem;
      }
      h2 {
        font-size: 1.45rem;
        margin-top: 2rem;
        margin-bottom: 2rem;
      }
      form {
        padding-left:10px;
      }
      .row {
        margin-bottom: 1rem;
      }
      .row .row {
        margin-top: 1rem;
        margin-bottom: 0;
      }
      [class*="col-"] {
        padding-top: 1rem;
        padding-bottom: 1rem;
        background-color: rgba(86,61,124,.15);
        border: 1px solid rgba(86,61,124,.2);
      }
      hr {
        margin-top: 2rem;
        margin-bottom: 2rem;
      }
      .lead, small {
        padding-left:10px;
      }
      footer {padding: 2rem;}
  </style>

  <!-- Google Tag Manager DELETE -->
  <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-K8V5396');</script>
  <!-- End Google Tag Manager DELETE -->

  </head>

  <body>
    <div class="container">

      <h1>Free .htaccess Generator</h1>
      <p class="lead">Simple, free and online. Create, without error, your .htaccess file.</p>
      <hr>
      <h3>Instructions</h3>
      <p>Fill the options and push "generate" button in order to get your .htaccess file. The copy and paste the content into your .htaccess file. Remember, this file must be in the root of your site.</p>

       <form>

        <h2>Public access options</h2>
        <div class="form-group">
          <label for="htDomain">Domain</label>
          <input type="text" class="form-control" id="htDomain" aria-describedby="Domain" placeholder="Enter domain">
          <small id="domainHelp" class="form-text text-muted">Example: domain.com (don't use www or http)</small>
        </div>

        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htHttps" class="form-check-input">
            Redirect http to https (SSL)
          </label>
        </div>
        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htWww" class="form-check-input">
            Force www access (default is non www)
          </label>
        </div>

        <br/>

        <h2>Config website</h2>

        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="ht404Redirect" class="form-check-input">
            Prevent 404 errors for non-existing folders
          </label>
        </div>

        <br/>

        <div class="form-group">
          <label for="htDefaultPage">Default access page</label>
          <input type="text" class="form-control" id="htDefaultPage" aria-describedby="Default page" placeholder="Enter default page (file)">
          <small class="form-text text-muted">Example: index.php index.html (default is index.html)</small>
        </div>

        <div class="form-group">
          <label for="htWebCharset">Default web charset</label>
          <input type="text" class="form-control" id="htWebCharset" aria-describedby="Web charset" placeholder="Enter default charset">
          <small class="form-text text-muted">Example: UTF-8</small>
        </div>

        <div class="form-group">
          <label for="htForceDownload">Force download (filetype)</label>
          <input type="text" class="form-control" id="htForceDownload" aria-describedby="Force download" placeholder="Enter files to force download when access">
          <small class="form-text text-muted">Example: .avi .pdf .mp4</small>
        </div>

        <div class="form-group">
          <label for="htFileSize">Limit upload file size</label>
          <input type="text" class="form-control" id="htFileSize" aria-describedby="File size" placeholder="Enter maximun file size in bytes">
          <small class="form-text text-muted">Example: 2147483647 (2GB)</small>
        </div>

        <div class="form-group">
          <label for="htAdminEmail">Administrator email</label>
          <input type="text" class="form-control" id="htAdminEmail" aria-describedby="Admin email" placeholder="Enter default contact email">
          <small class="form-text text-muted">Example: webmaster@domain.com</small>
        </div>

         <h2>Performance</h2>

         <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htGzip" class="form-check-input">
            Enable Gzip compression
          </label>
        </div>
        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htKeepAlive" class="form-check-input">
            Enable Keep-Alive header
          </label>
        </div>
        <br/>

         <div class="form-group">
            <label for="htExpiresHeaders">Expires Headers</label>
            <input type="text" class="form-control" id="htExpiresHeadersFormat" value="flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav">

            <div class="form-row">
              <div class="col-10" style="background-color:white; border:0;">
              <input type="text" class="form-control" id="htExpiresHeaders" aria-describedby="Expires headers" placeholder="Set the time for headers to expire (seconds)">
              <small class="form-text text-muted">Example: 29030400</small>
              </div>
              <div class="col-md-2" style="background-color:white; border:0;">
                <select class="form-control" onchange="$('#htExpiresHeaders').val($(this).val());">
                  <option>Time helper</option>
                  <option value="1800">30 min</option>
                  <option value="3600">1 hour</option>
                  <option value="43200">12 hours</option>
                  <option value="86400">1 day</option>
                  <option value="604800">1 week</option>
                  <option value="2419200">1 month</option>
                  <option value="29030400">1 year</option>
                </select>
              </div>
            </div>
        </div>

        <h2>Custom errors pages</h2>

        <div class="form-group">
          <label for="htCustomError404">Error 404</label>
          <input type="text" class="form-control" id="htCustomError404" aria-describedby="Custom 404" placeholder="Enter default 404 url">
          <small class="form-text text-muted">Example: error404.html</small>
        </div>

        <div class="form-group">
          <label for="htCustomError500">Error 500</label>
          <input type="text" class="form-control" id="htCustomError500" aria-describedby="Custom 500" placeholder="Enter default 500 url">
          <small class="form-text text-muted">Example: error500.html</small>
        </div>

        <h2>Security</h2>

        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htDirectory" class="form-check-input">
            Prevent directory navigation
          </label>
        </div>
         <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htDisableCgi" class="form-check-input">
            Disable CGI execution
          </label>
        </div>
        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htDisableTech" class="form-check-input">
            Hide information about web server technology
          </label>
        </div>
        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htDisableFrame" class="form-check-input">
            Do not allow pages to be framed
          </label>
        </div>
        <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htDisableSign" class="form-check-input">
            Disable server sign
          </label>
        </div>
         <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htSpamBots" class="form-check-input">
            Block SPAM bots
          </label>
        </div>
         <div class="form-check">
          <label class="form-check-label">
            <input type="checkbox" id="htIllegal" class="form-check-input">
            Prevent illegal or unsafe access (restrictive mode)
          </label>
        </div>

        <br/>
        <div class="form-group">
          <label for="htDisallowScript">Disallow script execution</label>
          <input type="text" class="form-control" id="htDisallowScript" aria-describedby="Disallow Script" placeholder="Enter scripts to prevent the execution">
          <small class="form-text text-muted">Example: .php .jsp .cgi</small>
        </div>

        <div class="form-group">
          <label for="htDenyRequests">Deny requests methods</label>
          <input type="text" class="form-control" id="htDenyRequests" aria-describedby="Disallow request" placeholder="Enter methods to deny">
          <small class="form-text text-muted">Example: get|post|put</small>
        </div>

         <div class="form-group">
          <label for="htHotlinking">Prevent hotlinking</label>
          <input type="text" class="form-control" id="htHotlinking" aria-describedby="Prevent hotlinking" placeholder="Enter full image URL you want to show when someone uses your hosted images">
          <small class="form-text text-muted">Example: https://mydomain.com/mylogo.png</small>
        </div>

        <br/><br/>
        <button type="button" id="generateHtaccess" class="btn btn-primary">Generate .htaccess</button>
      </form>

      <br/>
      <textarea id="htaccessFinal" rows="15" class="form-control"></textarea>

      <footer class="text-center">Created by Emirodgar</a> - <b>Free htaccess generator</b></footer>


      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/js/bootstrap.min.js" integrity="sha384-a5N7Y/aK3qNeh15eJKGWxsqtnX/wWdSZSKp+81YjTmS15nvnvxKHuzaWwXHDli+4" crossorigin="anonymous"></script>

      <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="   crossorigin="anonymous"></script>

      <script>
        $('#generateHtaccess').click( function()
           {
             var htaccess = '';
             var domain = $('#htDomain').val();
             var domainReg = domain.replace(/\./g,'\\.');
             if (domainReg =='') domainReg = 'CHANGEDOMAIN\\.com';
             var param = paramHttps = htaccessIllegal = htaccessSpam = '';
             var rewrite = false;
             $('#htaccessFinal').val('');
             htaccess += '\nRewriteEngine On';
             if ($('#htHttps').is(":checked"))
             {
               paramHttps = 's';
               htaccess +=  "\n\n#Redirect to SSL version"+
                            "\nRewriteCond %{HTTPS} off" +
                            "\nRewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}";
             }
             if ($('#htWww').is(":checked")) {
               htaccess +=  "\n\n#Redirect to www version"+
                            "\nRewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]" +
                            "\nRewriteRule ^(.*)$ http"+paramHttps+"://www.%{HTTP_HOST}/$1";
             } else {
              $param = 'www.';
              htaccess += "\n\n#Redirect to non www version"+
                          "\nRewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]" +
                          "\nRewriteRule ^(.*)$ http"+paramHttps+"://%1/$1 [R=301,L]";
            }
            //Config
            if ($('#ht404Redirect').is(":checked"))
             {
               htaccess +=  "\n\n#Prevent 404 en non-existing folders"+
                            "\nOptions -MultiViews";
             }
            var htDefaultPage = $('#htDefaultPage').val();
            if(htDefaultPage!=''){
               htaccess += "\n\n#Default page"+
                            "\nDirectoryIndex "+htDefaultPage;
            }
            var htAdminEmail = $('#htAdminEmail').val();
            if(htAdminEmail!=''){
               htaccess +=  "\n\n#Default contact email"+
                            "\nSetEnv SERVER_ADMIN "+htAdminEmail;
            }
            var htForceDownload = $('#htForceDownload').val();
            if(htForceDownload!=''){
               htaccess +=  "\n\n#Force download"+
                            "\nAddType application/octet-stream  "+htForceDownload;
            }
            var htWebCharset = $('#htWebCharset').val();
            if(htWebCharset!=''){
               htaccess +=  "\n\n#Default charset"+
                            "\nAddDefaultCharset "+htWebCharset;
            }
            var htFileSize = $('#htFileSize').val();
            if(htFileSize!=''){
               htaccess +=  "\n\n#Limit upload file size"+
                            "\nLimitRequestBody  "+htFileSize;
            }
             //Performance
            if ($('#htGzip').is(":checked")) {
               htaccess += "\n\n#Gzip compression"+
                            "\n<IfModule mod_gzip.c>"+
                            "\n   mod_gzip_on       Yes"+
                            "\n   mod_gzip_dechunk  Yes"+
                            "\n   mod_gzip_item_include file      .(html?|txt|css|js|php|pl)$"+
                            "\n   mod_gzip_item_include handler   ^cgi-script$"+
                            "\n   mod_gzip_item_include mime      ^text/.*"+
                            "\n   mod_gzip_item_include mime      ^application/x-javascript.*"+
                            "\n   mod_gzip_item_exclude mime      ^image/.*"+
                            "\n   mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*"+
                            "\n</IfModule>";
            }
            if ($('#htKeepAlive').is(":checked")) {
               htaccess += "\n\n#Enable Keep-Alive Headers"+
                            "\n<IfModule mod_headers.c>"+
                            "\n   Header set Connection Keep-Alive"+
                            "\n</IfModule>";
            }
            var htExpiresHeaders = $('#htExpiresHeaders').val();
            var htExpiresHeadersFormat = $('#htExpiresHeadersFormat').val();
            if(htExpiresHeaders!=''){
               htaccess += "\n\n#Set Expires Headers"+
                            '\n<FilesMatch "\.('+htExpiresHeadersFormat+')$">'+
                            "\n   ExpiresDefault A"+htExpiresHeaders+
                            "\n</FilesMatch>";
            }
             //Error
            var htCustomError404 = $('#htCustomError404').val();
            if(htCustomError404!=''){
               htaccess += "\n\n#Default 404 error"+
                            "\ErrorDocument 404 "+htCustomError404;
            }
            var htCustomError500 = $('#htCustomError500').val();
            if(htCustomError500!=''){
               htaccess += "\n\n#Default 500 error"+
                            "\nErrorDocument 500 "+htCustomError404;
            }
            //Security
            if ($('#htDirectory').is(":checked")) {
               htaccess += "\n\n#Prevent directory navigation"+
                            "\nOptions All -Indexes";
            }
            if ($('#htDisableCgi').is(":checked")) {
               htaccess += "\n\n#Disable CGI"+
                            "\nOptions -ExecCGI";
            }
            if ($('#htDisableTech').is(":checked")) {
               htaccess += "\n\n#Hide PoweredBy"+
                            "\nHeader unset X-Powered-By";
            }
            if ($('#htDisableFrame').is(":checked")) {
               htaccess += "\n\n#Do not allow pages to be framed"+
                            "\nHeader set X-Frame-Options SAMEORIGIN";
            }
            if ($('#htDisableSign').is(":checked")) {
               htaccess += "\n\n#Disable server sign"+
                            "\nServerSignature Off";
            }
            var htDisallowScript = $('#htDisallowScript').val();
            if(htDisallowScript!=''){
               htaccess += "\n\n#Disallow scripts execution"+
                            "\nAddHandler " +htDisallowScript;
            }
            var htDenyRequests = $('#htDenyRequests').val();
            if(htDenyRequests!=''){
               htaccess += "\n\n#Deny request method"+
                            "\nRewriteCond %{REQUEST_METHOD} !^("+htDenyRequests.toUpperCase()+")"+
                            "\nRewriteRule .? - [F]";
            }
            var htHotlinking = $('#htHotlinking').val();
            if(htHotlinking!=''){
               htaccess += "\n\n#Prevent hotlinking"+
                            "\nRewriteCond %{HTTP_REFERER} !^$"+
                            "\nRewriteCond %{HTTP_REFERER} !^http://(www\.)?"+domainReg+"/.*$ [NC]"+
                            "\nRewriteRule \.(gif|jpg|swf|flv|png)$ "+htHotlinking+" [R=302,L]";
            }
             if ($('#htSpamBots').is(":checked")) {
              rewrite= true;
              htaccessSpam = "\n\n   #Block Spam Bots"+
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(aesop_com_spiderman|alexibot|backweb|bandit|batchftp|bigfoot) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(black.?hole|blackwidow|blowfish|botalot|buddy|builtbottough|bullseye) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(cheesebot|cherrypicker|chinaclaw|collector|copier|copyrightcheck) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(cosmos|crescent|curl|custo|da|diibot|disco|dittospyder|dragonfly) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(drip|easydl|ebingbong|ecatch|eirgrabber|emailcollector|emailsiphon) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(emailwolf|erocrawler|exabot|eyenetie|filehound|flashget|flunky) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(frontpage|getright|getweb|go.?zilla|go-ahead-got-it|gotit|grabnet) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(grafula|harvest|hloader|hmview|httplib|httrack|humanlinks|ilsebot) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(infonavirobot|infotekies|intelliseek|interget|iria|jennybot|jetcar) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^(joc|justview|jyxobot|kenjin|keyword|larbin|leechftp|lexibot|lftp|libweb) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^web(zip|emaile|enhancer|fetch|go.?is|auto|bandit|clip|copier|master|reaper|sauger|site.?quester|whack) [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]" +
                          "\n   RewriteRule . - [F,L]";
            }
            if ($('#htIllegal').is(":checked")) {
              rewrite= true;
              htaccessIllegal = "\n\n   #Block illegal or unsafe access"+
                          "\n   RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]" +
                          "\n   RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|%0A|%0D).* [NC,OR]" +
                          "\n   RewriteCond %{HTTP_COOKIE} ^.*(<|>|'|'|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]" +
                          "\n   RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|'|'|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]" +
                          "\n   RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]" +
                          "\n   RewriteCond %{QUERY_STRING} ^.*(<|>|'|'|%0A|%0D|%27|%3C|%3E|%00).* [NC]" +
                          "\n   RewriteRule (.*) - [F,L]";
            }
            if (rewrite == true){
              htaccess += "\n\n#Mod Rewrite"+
                          "\n<IfModule mod_rewrite.c>"+
                          "\n   RewriteEngine On"+
                          "\n   Options +FollowSymlinks"+
                          "\n   RewriteBase /"+
                          htaccessSpam+
                          htaccessIllegal+
                          "\n</IfModule>";
            }
            $('#htaccessFinal').val(htaccess);
           }
        );
      </script>

    </div>
  </body>
</html>

Guardas el *.html y lo ejecutas en tu navegador web favorito.

Ejemplo…

Generador online de .htaccess 2

 

Si crees que esta herramienta es útil, compártela.

 

Una respuesta

  1. Roman
    18/03/2019

Agregar comentario