How to rewrite a URL

Asked

Viewed 90 times

0

Good afternoon, everyone. Could you help me with my question ? I wanted to rewrite a URL.

For example:

<a href="#Contato">Contato</a>

which points to a DIV Contact ID, however, the URL is:

https://site.com/index.php#Contato

and wanted you to stay:

https:site.com/Contato

I have tried to configure htaccess, however, nothing has changed :(

  • this "https:site.com/contact" url is invalid, that’s exactly what you want to do?

  • URL rewrite is done on the server.. A tag <a> you can put the link as you like, but it will not be guaranteed that the server will recognize that URL. Look for "friendly urls" on the web and see how they do on different servers (Nginx, apache, IIS, etc..) (one of the first responses of the research)

  • Relevant link: https://pt.meta.stackoverflow.com/q/499/132

1 answer

0

If you want to literally redirect to the url, just remove the "#", getting

<a href="Contato">Contato</a>

Now if you want to maintain the anchor function and just change the url visually without doing a redirect, you need the history pushState.

Example:

<a href="#Contato" onclick="history.pushState('Contato','Titulo contato','/Contato'); return false;">Contato</a>

Source: http://www.tidbits.com.br/pushstate-no-html-pra-mudar-a-url-do-browser-sem-dar-refresh

Browser other questions tagged

You are not signed in. Login or sign up in order to post.