21 hacks de htaccess que todo desarrollador debería conocer

La configuración del archivo .htaccess de Apache (hypertext access) puede ser una herramienta muy ponderosa en el desarrollo web si se utiliza de la forma adecuada. Mediante .htaccess podremos realizar redirecciones, proteger archivos y directorios con contraseña, prevenir el hotlinking y el robo de ancho de banda, comprimir archivos y mucho, mucho más. Entérate cómo“.
http://www.elwebmaster.com/articulos/21-hacks-de-htaccess-que-todo-desarrollador-deberia-conocer

Best .htaccess Hacks For Websites 

Tips y hacks para el archivo de configuración del servidor apache, .htaccess. “The .htaccess configuration file on your server which controls Apache Server is an important file and a very powerful tool for your website if used properly. It is generally found in root of your web server. In this article I will share how .htaccess can help improve your website’s stability, security, functionality and usability.”
https://priteshgupta.com/2011/05/best-htaccess-hacks-website/

Redirigir páginas de idiomas en Prestashop con .htaccess

Redirigir páginas de idiomas en Prestashop con .htaccess

 Un post recuperado de KnowHow

Para redirigir una URL de Prestashop de un idioma a otro podemos lograrlo de forma muy sencilla y rápida con el archivo .htaccess, el archivo de configuración del servidor Apache


Aunque hay formas más complicadas y completas de hacerlo, el código que os muestro funcionará correctamente; menos es más… Para ello, accedemos a nuestro hosting, bien vía FTP con algún programa cliente como Filezilla, o por la gestión de archivos de nuestro hosting y añadimos la siguiente línea de código:

#Redirigimos la página del idioma inglés (/en) de nuestra tienda online a la página española (/es)
Redirect 301 /en http://www.midominio.com/es

Si queremos hacerlo con más idiomas que tengamos instalados en nuestra tienda online con PrestaShop, añadiremos una línea de código similar por página de idioma:

Redirect 301 /en http://www.midominio.com/es

Redirect 301 /fr http://www.midominio.com/es

OJO! Recordemos siempres hacer una copia del archivo .htacces original. 
La página que queremos redirigir no debe escribirse con la dirección completa, es decir http://www.midominio.com/en se escribiría solo /en. A la dirección que queremos redirigirla si que tiene que escribirse con la URI completa: http://www.midominio.com/es

Y con eso, ya lo tenemos. Dejo un ejemplo de archivo .htaccess de PrestaShop con la redirección 301 del idioma inglés y francés a la página en castellano:

EJEMPLO REDIRECCIÓN IDIOMAS EN PRESTASHOP CON HTACCESS

# ~~start~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
# .htaccess automaticaly generated by PrestaShop e-commerce open-source solution
# http://www.prestashop.com – http://www.prestashop.com/forums
# GBP REDIRIJO IDIOMAS A LA VERSIÓN ESPAÑOLA
Redirect 301 /en http://www.midominio.com/es
Redirect 301 /fr http://www.midominio.com/es



SetEnv HTTP_MOD_REWRITE On

RewriteEngine on

#Domain: midominio.com
RewriteRule . – [E=REWRITEBASE:/]
RewriteRule ^api$ api/ [L]
RewriteRule ^api/(.*)$ %{ENV:REWRITEBASE}webservice/dispatcher.php?url=$1 [QSA,L]
# Images
RewriteRule ^([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$1$2$3.jpg [L]
RewriteRule ^([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$1$2$3$4.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$1$2$3$4$5.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg [L]
RewriteRule ^([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg [L]
RewriteRule ^c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/c/$1$2$3.jpg [L]
RewriteRule ^c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ %{ENV:REWRITEBASE}img/c/$1$2.jpg [L]
# AlphaImageLoader for IE and fancybox
RewriteRule ^images_ie/?([^/]+).(jpe?g|png|gif)$ js/jquery/plugins/fancybox/images/$1.$2 [L]
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ – [NC,L]
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]

AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType font/otf .otf
AddType application/x-font-woff .woff


Header add Access-Control-Allow-Origin “*”

#If rewrite mod isn’t enabled
ErrorDocument 404 /index.php?controller=404
# ~~end~~ Do not remove this comment, Prestashop will keep automatically the code outside this comment when .htaccess will be generated again
AddHandler x-mapp-php5.5  .php

Redirigir http a https con .htaccess

Redirigir http a https con .htaccess
Valencia, 17/04/2019
Si quieres redirigir tu web del protocolo http al protocolo seguro https, puedes hacerlo modificando el archivo de configuración del servidor Apache, el .htaccess. recuerda siempre hacer una copia de seguridad primero. Puedes ver más información al respecto en este enlace de imaginanet.com.
Este es el código:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://TUDOMINIO.COM/$1 [R=301,L]
Nota importante
Si tu gestor de contenidos o CMS es WordPress, no cambies http por https en tu Escritorio o Dashboard (Ajustes -Generales). En vez de eso, instala un plugin tipo Really Simple SSL. Lo encontrarás en el repositorio de WordPress, es decir, desde tu Escritorio de WordPress ->Plugins ->Añadir nuevo.

Redirigir páginas de Error 404 en PrestaShop a la Home

Artículo del blog de Hector Nevado (www.hnevado.es/blog) para redirigir las páginas de Error 404 en PrestaShop a la página de inicio o Home. Funciona perfectamente. Mil gracias desde aquí!

https://www.hnevado.es/blog/redireccionar-errores-404-a-la-home-en-prestashop/ 

<?php
/*
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA 
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/


class PageNotFoundControllerCore extends FrontController
{
public $php_self = 'pagenotfound';
public $page_name = 'pagenotfound';
public $ssl = true;

/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
/** AÑADO TEMA REDIRECCION ERRORES
*/
{
Tools::redirect();
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');

if (preg_match('/.(gif|jpe?g|png|ico)$/i', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
$this->context->cookie->disallowWriting();
if (!isset($_SERVER['REDIRECT_URL'])) {
$_SERVER['REDIRECT_URL'] = '';
if (preg_match('@^'.__PS_BASE_URI__.'([0-9]+)-([_a-zA-Z0-9-]+)(/[_a-zA-Z0-9-]+)?.jpg$@', $_SERVER['REQUEST_URI'], $matches)) {
$_SERVER['REDIRECT_URL'] = __PS_BASE_URI__.'p/'.Image::getImgFolderStatic($matches[0]).'/'.$matches[0].'-'.$matches[1].'.jpg';
}

}
if (preg_match('#/p[0-9/]*/([0-9]+)-([_a-zA-Z]*).(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
// Backward compatibility since we suffixed the template image with _default
if (Tools::strtolower(substr($matches[2], -8)) != '_default') {
header('Location: '.$this->context->link->getImageLink('', $matches[1], $matches[2]), true, 302);
exit;
} else {
$image_type = ImageType::getByNameNType($matches[2], 'products');
if ($image_type && count($image_type)) {
$root = _PS_PROD_IMG_DIR_;
$folder = Image::getImgFolderStatic($matches[1]);
$file = $matches[1];
$ext = '.'.$matches[3];

if (file_exists($root.$folder.$file.$ext)) {
if (ImageManager::resize($root.$folder.$file.$ext, $root.$folder.$file.'-'.$matches[2].$ext, (int)$image_type['width'], (int)$image_type['height'])) {
header('HTTP/1.1 200 Found');
header('Status: 200 Found');
header('Content-Type: image/jpg');
readfile($root.$folder.$file.'-'.$matches[2].$ext);
exit;
}
}
}
}
} elseif (preg_match('#/c/([0-9]+)-([_a-zA-Z]*).(png|jpe?g|gif)$#', $_SERVER['REDIRECT_URL'], $matches)) {
$image_type = ImageType::getByNameNType($matches[2], 'categories');
if ($image_type && count($image_type)) {
$root = _PS_CAT_IMG_DIR_;
$file = $matches[1];
$ext = '.'.$matches[3];

if (file_exists($root.$file.$ext)) {
if (ImageManager::resize($root.$file.$ext, $root.$file.'-'.$matches[2].$ext, (int)$image_type['width'],
(int)$image_type['height'])) {
header('HTTP/1.1 200 Found');
header('Status: 200 Found');
header('Content-Type: image/jpg');
readfile($root.$file.'-'.$matches[2].$ext);
exit;
}
}
}
}

header('Content-Type: image/gif');
readfile(_PS_IMG_DIR_.'404.gif');
exit;
} elseif (in_array(Tools::strtolower(substr($_SERVER['REQUEST_URI'], -3)), array('.js', 'css'))) {
$this->context->cookie->disallowWriting();
exit;
}

parent::initContent();

$this->setTemplate(_PS_THEME_DIR_.'404.tpl');

}

protected function canonicalRedirection($canonical_url = '')
{
// 404 - no need to redirect to the canonical url
}

protected function sslRedirection()
{
// 404 - no need to redirect
}
}