.htaccess error when uploading to server

3

I had previously posted this question how to create friendly URLs without losing css and js e imágenes .

In localhost works perfectly without any problem. The problem arose when uploading to the server hostgator ( main domain linked to the server ) the URLs friendly does not work www.example.com/online/video/hd/free/ sends me directly to 404 error page

Perform tests with other friendly urls from another file .htaccess to see if the server was accepting or not accepting the URLs friendly but it worked perfectly without any problem.

The problem is in this file .htaccess or rather in the path RewriteBase /project/

In localhost the project is: project - > localhost/project/index.php

  

He mentioned precisely that the error is in the route RewriteBase /project/ because in localhost if the name of the project does not exist or if it exists and the name or other name that is not: project the same error occurs on the server, the same error I'm having.

# Activamos mod_rewrite
RewriteEngine on

# Seleccionamos el directorio base para el RewriteRule
RewriteBase /project/

# Aquí nos evitamos comprobar que sea un archivo (agrego comprobación
# para detectar también directorio) en cada conjunto de reglas
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ $1 [QSA,L]

# Obtenemos todo lo que vaya tras "assets/" y subdirectorios previstos
RewriteCond %{REQUEST_URI} assets/(css|fonts|js|img)/(.+)$
# Entonces (si se cumplen todas las condiciones) redirigimos (R)
# y dejamos de evaluar el resto de reglas (L)
RewriteRule ^(.*)$ assets/%1/%2 [L,R]

# Tu/s regla/s
RewriteRule ^online-video-en-hd-gratis/?$ video.php [L,NC,QSA]
RewriteRule ^online/video/hd/free/?$ online.php [L,NC,QSA]

I have tried this way: RewriteBase /www.example.com/ and in this way RewriteBase /public_html/ but no success does not work.

  

NOTE: The example domain: www.example.com is direct in public_html without any other folder ie it does not have a folder like in the other additional domains that are the same in public_html but in a folder specifies a folder: OTRAPAGINA.COM

     

public_html (as you can see there exists the index.php equally the direct online.php in the folder public_html because it is linked to the main domain to the configured domain with the server.)

The Server is linux / apache perform tests with this .htaccess file and it worked fine by visiting the following URLs www.example.com/online/video/hd/free/

RewriteEngine on
RewriteRule ^online/video/hd/free/$ online.php [L,NC,QSA]

The specific URLs is: www.example.com/online.php

But in the .htaccess file I'm having problems visiting the same URL www.example.com/online/video/hd/free/ redirects me to 404 error page.

Also, then I plan to use a second structure:

public_html -> EXAMPLE.COM(<- carpeta) -> online.php

If it were not the main domain, if not an additional domain and it was like this, how should I modify the .htaccess ?

    
asked by J. Mick 08.01.2017 в 03:00
source

1 answer

2

The directive RewriteBase specifies the prefix of the URL that is used as the base ( per directory in .htaccess ) in all RewriteRule . It is necessary when relative routes are used.

For example, it serves so that the directives:

RewriteEngine On
RewriteRule ^carpeta/usuarios$  /carpeta/usuarios.php
RewriteRule ^carpeta/publicaciones$  /carpeta/publicaciones.php

Are equivalent (but saving some characters) to:

RewriteEngine On
RewriteBase /carpeta
RewriteRule ^usuarios$  /usuarios.php
RewriteRule ^publicaciones$  /publicaciones.php

1. Change the RewriteBase to apply to the root of the site

In the case of your site, you are working on the root domain , so simply change the line:

# Seleccionamos el directorio base para el RewriteRule
RewriteBase /project/

By:

# Seleccionamos el directorio base para el RewriteRule
RewriteBase /

2. Second domain

Regarding your second question, it depends on whether public_html/EXAMPLE.COM is a second domain configured in that way (it would seem that way), or if you simply access a folder with that name.

  • If it's a second domain

    Being another domain, the DocumentRoot of http://example.com will directly work on that folder, so it would not be necessary to change anything, since http://example.com/online.php will search inside that folder, without needing to rewrite the URL.

    That is, it would be valid to work also with:

    RewriteBase /
    
  • If it is not configured as a domain (I do not think this is the case)

    If the requests are addressed to, for example: http://tusitio.com/EXAMPLE.COM/online.php ; then a RewriteBase could be used as the following to avoid having to use the absolute path:

    RewriteEngine On
    RewriteBase /EXAMPLE.COM
    
  • answered by 08.01.2017 / 04:37
    source