Modify url if there is no php

1

I'm managing the url with .htaccess and, internally, I'm validating the URL.

For example, when the URL that is accessed is the following:

home.dev/control/principal/index

Rewrite where the file is with the following structure:

home.dev/aplicacion/carpeta/archivo

That's the right way, and when they misspell for example like this:

    home.dev/control/principale/indexar

internally it is valid and since it does not exist it redirects it to main. But the URL remains as it was written.

Is there a way for it to be written badly other than to perform the redirect change the URL?

    
asked by Pablo Moraga 31.10.2017 в 17:01
source

1 answer

0

You are currently rewriting an address. The idea is that in addition redirects
(with the flag [R] ).

RewriteEngine On

# Reescribir (internamente)
# control/principal/cualquier-archivo
#  ->  aplicacion/carpeta/cualquier-archivo
RewriteRule ^control/principal(?:/(.*))?$ aplicacion/carpeta/$1 [NC,L]

# Redireccionar (cambia la URL) 
# cuando no existe el directorio (-d) 
# ni el archivo (-f)
# al home
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ control/principal/index.php [NC,R,L]

Alternatively, you could do that when you can not find the file, the 404 error is your own home, using the directive ErrorDocument . In this way, the client learns that the address does not exist, but still sees the main page. -It's different from what you asked for, but I would do it that way.

ErrorDocument 404 /aplicacion/carpeta/index.php
    
answered by 26.11.2017 в 01:42