• ¡Bienvenido a XenFácil!

    Estás viendo el sitio como Invitado. Para poder participar en este sitio

    y obtendrás privilegios adicionales, acceso a otras áreas y mucho mas.

    ¡Es gratis!


    ¿Ya eres miembro? Inicia sesión

Ayuda Duda .htaccess

armic

XenForoUser
Mensajes
20
Puntuación de reacciones
1
Puntos
3
País
España
Versión de XenForo
1.0.x
Página web
Web
Buenas tardes,

Actualmente tengo la página redirigida hacia la carpeta de "foro" a traves del archivo .htaccesss y me pregunto si es posible simplificarlo o mejorarlo.

Las necesidades son las siguientes:
  • Redireccionar la página de inicio a la carpera de "foro"
  • Que siempre aparezcan las "WWW"
  • Que siempre se fuerze la página en "https"
Decir que actualmente, con la configuración de abajo, no tengo problemas, pero desconozco si se puede mejorar/simplificar.
Insertar CODE, HTML o PHP:
RewriteOptions inherit

RewriteEngine On



# Forzar "https"

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]



# Forzar las 3 "www"

RewriteCond %{HTTP_HOST} !^www\.miforo\.com

RewriteRule (.*) https://www.miforo.com/$1 [R=301,L]



# Forzar redirección a "foro"

RewriteCond %{HTTP_HOST} ^.*$

RewriteRule ^/?$ "https\:\/\/www\.miforo\.com\/foro/" [R=301,L]



AuthName "Privado"

AuthUserFile "/home/miforo/.htpasswds/public_html/passwd"


RewriteRule .*\.()$ - [F,NC]



Dicho esto, una vez en la carpeta "foro", esta tiene el HTACCESS que crea por defecto Xenforo, pero tiene la pega de que se puede acceder sin usar las 3 "W", y sin usar "https" (o ambas a la vez). He intentado obligar a través de dicho archivo de que siempre use esas dos cosas, pero no logro que funcione, así que no se si estoy haciendo algo mal, o colocando el código en un lugar incorrecto del archivo.

Este es el archivo por defecto en la raiz de Xenforo:

Insertar CODE, HTML o PHP:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Muchas gracias!
 

lms

Administrador
Mensajes
7.741
Puntuación de reacciones
2.163
Puntos
2.613
Sitio web
xenfacil.com
País
España
Versión de XenForo
2.1.x
PayPal
Donar dinero a este usuario
Página web
Web
Yo uso este:
Insertar CODE, HTML o PHP:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    ##########################################################################################

    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://www.miforo.com%{REQUEST_URI} [R=301,L,QSA]

    RewriteCond %{HTTP_HOST} ^www\.miforo\.com [NC]
    RewriteRule ^(.*)$ https://www.miforo.com/$1 [L,R=301]
    
    ##########################################################################################
    
    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>
RewriteCond %{HTTP_HOST} ^miforo\.es$ [OR]
RewriteCond %{HTTP_HOST} ^www\.miforo\.es$
RewriteRule ^(.*)$ "https\:\/\/www\.miforo\.com\/$1" [R=301,L]

Salud2
 

Jack Franco

Nuevo
Mensajes
2
Puntuación de reacciones
0
Puntos
1
País
México
Versión de XenForo
Ninguna
Página web
Web
Buenas noches, sobre eso tengo una duda: en estos meses he visto algunos sitios que tienen el certificado HTTPS activo pero dicha web no muestra el candado verde de "seguro" alguien sabe porque no aparece eso? o necesita alguna configuracion extra en el archivo .htaccesss, gracias es una inquietud que siempre tuve
 

lms

Administrador
Mensajes
7.741
Puntuación de reacciones
2.163
Puntos
2.613
Sitio web
xenfacil.com
País
España
Versión de XenForo
2.1.x
PayPal
Donar dinero a este usuario
Página web
Web
Mira a ver si tienen certificado. El protocolo https requiere de un certificado válido para que aparezca el candado. Cuando el certificado del sitio es de confianza, aparece en verde. Si es autofirmado o genérico, no aparece.

Salud2
 

armic

XenForoUser
Mensajes
20
Puntuación de reacciones
1
Puntos
3
País
España
Versión de XenForo
1.0.x
Página web
Web
Buenas tardes, pues después de probar los códigos que comentas, me aparece el error de que la pagina "tiene muchas redirecciones" cuando intento acceder a ella.


Y el usado en "miforo.com/foro" es el siguiente, y ahora ya me fuerza el https, pero sigue sin forzarme las "WWW", ya que si lo pongo, me salta un error que no me deja acceder a la pagina porque dice que hay muchas redirecciones. El .htaccess del root del dominio sigue siendo el del primer post.

Insertar CODE, HTML o PHP:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
   
    ##########################################################################################

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

   
    ##########################################################################################
   

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Muchas gracias!
 

lms

Administrador
Mensajes
7.741
Puntuación de reacciones
2.163
Puntos
2.613
Sitio web
xenfacil.com
País
España
Versión de XenForo
2.1.x
PayPal
Donar dinero a este usuario
Página web
Web
Rich (BB code):
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
  
    ##########################################################################################

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
   RewriteCond %{HTTPS} off
   RewriteRule (.*) https://www.miforo.com%{REQUEST_URI} [R=301,L,QSA]

  
    ##########################################################################################
  

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Muchas gracias!
Te lo he modificado algo. El RewriteRule (.*) https://www.miforo.com%{REQUEST_URI} [R=301,L,QSA] equivale al %{HTTP_HOST} con la diferencia que éste último funciona tanto para con que sin www.

salud2
 

armic

XenForoUser
Mensajes
20
Puntuación de reacciones
1
Puntos
3
País
España
Versión de XenForo
1.0.x
Página web
Web
Buenas tardes, pues nada, sigo algo mejor, pero me sigue fallando un poco. No me fuerza las www en https una ocasión, es decir:

http://www.miforo.com/foro (redirecciona a https)

http://miforo.com/foro (redirecciona a https y www)

https://miforo.com/foro (NO redirecciona a www)


Gracias!
 

lms

Administrador
Mensajes
7.741
Puntuación de reacciones
2.163
Puntos
2.613
Sitio web
xenfacil.com
País
España
Versión de XenForo
2.1.x
PayPal
Donar dinero a este usuario
Página web
Web
Prueba así:
Insertar CODE, HTML o PHP:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
  
    ##########################################################################################

    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

  
    ##########################################################################################
  

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>
   RewriteCond %{HTTP_HOST} ^miforo\.es$ [OR]
   RewriteCond %{HTTP_HOST} ^www\.miforo\.es$
   RewriteRule ^(.*)$ "https\:\/\/www\.miforo\.com\/$1" [R=301,L]

Salud2
 

armic

XenForoUser
Mensajes
20
Puntuación de reacciones
1
Puntos
3
País
España
Versión de XenForo
1.0.x
Página web
Web
Buenas tardes,

Creo que ya lo tengo solucionado con el código que he pongo a continuación.

El codigo que me habias puesto, funciona, pero en mi caso, era parcialmente.


Si quitaba las www del siguiente enlace:

https://www.miforo.com/foro/forums/1/


Eliminaba el apartado de "foro" y me redireccionaba al siguiente enlace con el consiguiente error 404:

https://www.miforo.com/forums/1/



Después de todo esto, me surge la duda de para que sirve el flag "QSA", el cual, por lo que he visto acorta la url dependiendo de si está o no, pero no lo acabo de entender. ¿Podrías explicarme en palabras de un profano en la materia su significado?

Insertar CODE, HTML o PHP:
#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 405 default
ErrorDocument 406 default
ErrorDocument 500 default
ErrorDocument 501 default
ErrorDocument 503 default

<IfModule mod_rewrite.c>
    RewriteEngine On
 
    ##########################################################################################

    # Forzar "https"
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.miforo.com%{REQUEST_URI} [R=301,L,QSA]

    # Forzar las 3 "www"
    RewriteCond %{HTTP_HOST} ^miforo\.com$
    RewriteRule ^(.*)$ https://www.miforo.com%{REQUEST_URI} [R=301,L]

 
    ##########################################################################################
 

    #    If you are having problems with the rewrite rules, remove the "#" from the
    #    line that begins "RewriteBase" below. You will also have to change the path
    #    of the rewrite to reflect the path to your XenForo installation.
    #RewriteBase /xenforo

    #    This line may be needed to enable WebDAV editing with PHP as a CGI.
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
</IfModule>

Muchas gracias por todo
 
Última edición:

armic

XenForoUser
Mensajes
20
Puntuación de reacciones
1
Puntos
3
País
España
Versión de XenForo
1.0.x
Página web
Web
Bueno, y el htaccess del root también lo he simplificado y el Google PageSpeed Insights ya no me dice tengo muchas redirecciones. Ah! Importante colocar primero la redireccion a "foro" y después el resto, que parece una tontería pero se gana algo, al menos de cara al test de Google.

Desconozco si aún se podría mejorar algo más.

Insertar CODE, HTML o PHP:
RewriteOptions inherit

RewriteEngine On


# Forzar redirección a "foro"

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ "https\:\/\/www\.miforo\.com\/foro/" [R=301,L]


# Forzar "https y 3 "www""

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.miforo\.com
RewriteRule ^(.*)$ https://www.miforo.com%{REQUEST_URI} [R=301,L]



AuthName "Privado"

AuthUserFile "/home/miforo/.htpasswds/public_html/passwd"


RewriteRule .*\.()$ - [F,NC]

Gracias!
 

lms

Administrador
Mensajes
7.741
Puntuación de reacciones
2.163
Puntos
2.613
Sitio web
xenfacil.com
País
España
Versión de XenForo
2.1.x
PayPal
Donar dinero a este usuario
Página web
Web
Modificación de la cadena de consulta

De forma predeterminada, la cadena de consulta se pasa sin cambios. Sin embargo, se pueden crear URLs en la cadena de sustitución que contengan una parte de la cadena de consulta. Simplemente usar un signo de interrogación dentro de la cadena de sustitución para indicar que el siguiente texto debe ser reinyectado en la cadena de consulta. Cuando se desea borrar una cadena de consulta existente, hay que terminar la cadena de sustitución con sólo un signo de interrogación. Para combinar cadenas de consulta nuevas y viejas, hay que usar el indicador [QSA].

QSA - Query String Append (Agregar Cadena de consulta)
L = Last rule (Última regla)
Esta regla agrega la cadena de consulta GET resultante de la regla de ReWritea la cadena de consulta GET inicial enviada por el navegador. Por ejemplo, teniendo el siguiente RewriteRule:

PHP:
RewriteRule ^/product/([0-9]*)/?     /product.php?product_id=$1    [QSA]

Símplemente hace que el número product_id aparezca como un directorio al usuario. Ahora existen dos vías diferentes de visionar la página, view=short y view=long. Por la razón que sea, podemos no querer hacer que estas vistas aparezcan como directorios usando RewriteRule.Para ello se deberá hacer algo como:

PHP:
http://mysite.com/product/1351283/?view=shor

Ahora vemos cómo funciona QSA. Con QSA, la URL final reescrita es

PHP:
http://example.com/product.php?product_id=1351283&view=shor

QSA ha hecho que RewriteEngine agregue la cadena de consulta existente (view=short) a la nueva cadena de consulta (product_id=1351283). Sin QSA, la cadena de consulta existente se reemplaza por la nueva cadena de consulta:

PHP:
http://example.com/product.php?product_id=135128

Más información

Salud2
 
Arriba