Change the url to a friendly url

0

I'm having trouble changing the URL of the site I'm putting together, I've searched a lot of places and everyone is talking about using the .htaccess file. So far so good but I do the same as I researched and does not work.

Follow the files I tried to change the url.

RewriteEngine On
RewriteBase /
RewriteRule ^home index.php [NC,QSA,L]
RewriteRule ^contato contato.php [NC,QSA,L]


#############################################
RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^home(.*)$ index.php
RewriteRule ^contato(.*)$ contato.php


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

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^home/?$ /index.php [NC,L]
    RewriteRule ^contato/?$ /contato.php [NC,L]
</IfModule>

I tried with all these and it will not, the pages stay the same way www.site.com.br/index.php www.site.com.br/contato.php

This is either on localhost or on the web server.

    
asked by anonymous 01.04.2017 / 20:05

1 answer

0

First, and more importantly: are you using Apache as WebServer? Htaccess only works in Apache. If yes, see if AllowOverride is enabled in your httpd.conf (Directory configuration)

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Then, you have the urls inverted ... (from what I understood of your problem). You are doing the rewrite of "/ home" to "/index.php", not the other way around.

# Primeiramente, manda um 301 de volta para o cliente, para poder alterar a URL no navegador.
RewriteRule ^index\.php$ home [NC,L,R=301]
RewriteRule ^contato\.php$ contato [NC,L,R=301]
RewriteRule ^pagina\.php$ nomequalquer [NC,L,R=301]

# Depois, redireciona internamente a execução do script
RewriteRule ^home$ index.php [NC, L]
RewriteRule ^contato$ contato.php [NC, L]
RewriteRule ^nomequalquer$ pagina.php [NC, L]

There must be another more efficient way, but this is an option

    
01.04.2017 / 20:54