{"id":1730,"date":"2021-11-26T11:14:19","date_gmt":"2021-11-26T15:14:19","guid":{"rendered":"https:\/\/www.neothek.com\/soporte\/?post_type=kb&#038;p=1730"},"modified":"2022-04-29T12:35:25","modified_gmt":"2022-04-29T16:35:25","slug":"redirigir-sitio-web-usando-un-archivo-htaccess","status":"publish","type":"kb","link":"https:\/\/www.neothek.com\/soporte\/articulo\/redirigir-sitio-web-usando-un-archivo-htaccess\/","title":{"rendered":"Redirigir sitio web usando un archivo .htaccess"},"content":{"rendered":"<p style=\"text-align: justify;\">El <em>archivo .htaccess<\/em> (HyperText Access o Acceso de Hipertexto) se encuentra presente en el servidor apache, se utiliza para configurar funciones adicionales para sitios alojados en el servidor web apache. Su uso requiere de mucho cuidado ya que un m\u00ednimo error de sintaxis puede afectar la funcionalidad del sitio web.<\/p>\n<p style=\"text-align: justify;\">El archivo .htaccess se encuentra como oculto, necesitamos habilitar desde nuestro cliente FTP o desde cPanel la opci\u00f3n de poder ver archivos ocultos.<\/p>\n<p>Antes de crear o editar nuestro archivo .htaccess tomar en cuenta lo sgte:<\/p>\n<span class=\"mkb-shortcode-container\">\t\t<div class=\"mkb-tip\">\n\t\t\t<div class=\"mkb-tip__icon\">\n\t\t\t\t<i class=\"fa fa-lightbulb-o fa-lg\"><\/i>\n\t\t\t<\/div>\n\t\t\t<div class=\"mkb-tip__content\">\n\t\t\t\tEl archivo .htaccess solo modifica la configuraci\u00f3n del directorio donde esta presente y los subdirectorios pertenecientes, as\u00ed que siempre recomendamos colocar en el directorio principal public_html\t\t\t<\/div>\n\t\t<\/div>\n\t<\/span>\n<h2>Pasos a seguir para crear un archivo .htaccess<\/h2>\n<p style=\"text-align: justify;\">1. Crear un archivo de texto con un editor de texto plano como ser <em><strong>bloc de notas<\/strong><\/em> y guardar como <strong>htaccess.txt.<\/strong><\/p>\n<p style=\"text-align: justify;\"><span class=\"mkb-shortcode-container\">\t\t<div class=\"mkb-tip\">\n\t\t\t<div class=\"mkb-tip__icon\">\n\t\t\t\t<i class=\"fa fa-lightbulb-o fa-lg\"><\/i>\n\t\t\t<\/div>\n\t\t\t<div class=\"mkb-tip__content\">\n\t\t\t\tLa raz\u00f3n por la que se debe guardar como archivo htaccess.txt es porque muchos sistemas operativos y aplicaciones FTP no pueden leer o ver un archivo .htaccess por defecto. Una vez subido al servidor se puede renombrar el archivo a .htaccess.<\/p>\n\t\t\t<\/div>\n\t\t<\/div>\n\t<\/span>\n<p style=\"text-align: justify;\">2. Editar el contenido del archivo .htaccess. A continuaci\u00f3n, se muestran algunos ejemplos de redireccionamientos que se puede utilizar. Est\u00e1n etiquetados de acuerdo con las acciones que se efectuaran.<\/p>\n<h2>301 (Permanent) Redirect:<\/h2>\n<p>Utilice un .htaccess de redireccionamiento 301 para dirigir un sitio completo a una URL diferente de forma permanente. Este es el tipo de redireccionamiento m\u00e1s com\u00fan y es \u00fatil en la mayor\u00eda de situaciones. En este ejemplo, estamos redirigiendo al dominio \u00abexample.com\u00bb.<\/p>\n<p style=\"text-align: justify;\"><em>Cuando agregue lo sgte en el archivo .htaccess de su sitio web, aseg\u00farese\u00a0de reemplazar con su nombre de dominio.<\/em><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">RewriteEngine On \r\nRewriteCond %{HTTPS} off \r\nRewriteRule ^(.*)$ https:\/\/%{HTTP_HOST}%{REQUEST_URI} [L,R=301]<\/pre>\n<h2>302 (Temporary) Redirect:<\/h2>\n<p style=\"text-align: justify;\">Se redirecciona todo un sitio a una URL temporal diferente. Es muy \u00fatil para fines de SEO cuando se tiene una p\u00e1gina destino temporal y se planifica retornar a la p\u00e1gina de destino principal en una fecha posterior:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># This allows you to redirect your entire website to any other domain\r\nRedirect 302 \/ http:\/\/example.com\/\r\n<\/pre>\n<h2>Redireccionar index.html a un subdirectorio especifico:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># This allows you to redirect index.html to a specific subfolder\r\nRedirect \/index.html http:\/\/example.com\/newdirectory\/<\/pre>\n<h2 style=\"text-align: justify;\">Redireccionar un antiguo directorio a un nuevo directorio:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Redirects example.com\/old to example.com\/new\r\nRewriteRule ^old\/(.*)$ \/new\/$1 [R=301,NC,L]<\/pre>\n<h2>Redireccionar un archivo antiguo a una nueva ruta del archivo:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Redirect old file path to new file path\r\nRedirect \/olddirectory\/oldfile.html http:\/\/example.com\/newdirectory\/newfile.html<\/pre>\n<h2>Redireccionar a un subdirectorio con una url masking:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Show the content in example.com\/folder2, but the URL appears as example.com\/folder1\r\nRewriteEngine On\r\nRewriteRule ^folder1\/?$ \/folder2\/\r\n\r\n# To show the URL as just example.com\r\nRewriteEngine On\r\nRewriteRule ^\/?$ \/folder2\/\r\n<\/pre>\n<h2>Redireccionar a una pagina \u00edndex:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Provide Specific Index Page (Set the default handler)\r\nDirectoryIndex index.html<\/pre>\n<h2>Redireccionar a un mensaje de error:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Redirect 404 Error pages to the home page\r\nErrorDocument 404 http:\/\/example.com\/<\/pre>\n<h2>Redireccionar una p\u00e1gina no existente a index.php<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"># Redirect non-existing pages to index.php\r\nOptions +SymLinksIfOwnerMatch \r\nRewriteEngine On \r\nRewriteCond %{REQUEST_FILENAME} !-f \r\nRewriteCond %{REQUEST_FILENAME} !-d\r\nRewriteRule . \/index.php [L]\r\n<\/pre>\n<p>3. Finalmente subimos el archivo htaccess.txt y renombramos a .htaccess.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>El archivo .htaccess (HyperText Access o Acceso de Hipertexto) se encuentra presente en el servidor apache, se utiliza para configurar funciones adicionales para sitios alojados en el servidor web apache. Su uso requiere de mucho cuidado ya que un m\u00ednimo error de sintaxis puede afectar la funcionalidad del sitio web. El archivo .htaccess se encuentra [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"kbtopic":[13],"kbtag":[42,161,162],"class_list":["post-1730","kb","type-kb","status-publish","hentry","kbtopic-web-hosting","kbtag-htaccess","kbtag-redirigir","kbtag-redirigir-sitio-web"],"_links":{"self":[{"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kb\/1730","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kb"}],"about":[{"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/types\/kb"}],"author":[{"embeddable":true,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/comments?post=1730"}],"version-history":[{"count":21,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kb\/1730\/revisions"}],"predecessor-version":[{"id":1994,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kb\/1730\/revisions\/1994"}],"wp:attachment":[{"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/media?parent=1730"}],"wp:term":[{"taxonomy":"kbtopic","embeddable":true,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kbtopic?post=1730"},{"taxonomy":"kbtag","embeddable":true,"href":"https:\/\/www.neothek.com\/soporte\/wp-json\/wp\/v2\/kbtag?post=1730"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}