Friendly URL with JQuery

1

Hello, everyone!

My system is developed in JQuery, so I make changes to pages without loading, just with $ .get (). The big question is: even without loading, I need the URLs to be changed, making the system even more user friendly. I can already make the change perfectly, making all internal transactions fit perfectly with URL changes. However, when I refresh the page in the current URL, or when I want to enter through one of those URLs, it falls on a nonexistent page because everything is done only in index.html.

For example: The whole process is done in index.html, which calls some .js that do all that control. However, when I click on the "profile" button and present this page without uploading, I change the url to mysite.com/profile. The problem happens when I try to refresh this page. When updating, error 404 will appear because there is no index.html file in the "profile" folder. What I would like is that there was a treatment and that upon entering myite.com / profile, I would be redirected to the index.html? Page = profile, for example.

What can I do?

Thanks in advance!

    
asked by anonymous 29.11.2017 / 21:00

1 answer

1

You can do this by using the .htaccess file to point to a specific 404 error page and redirect it to index.html with the parameter in question.

1) Create a .html page in the root folder where 404 errors will be directed:

redir.html

2) Enter in the page redir.html the JavaScript code that will capture the parameter and make the redirect:

<script>
var url_ = location.href;
params = url_.split("/").pop();
location.href = "index.html?pagina="+params;
</script>
                                    
30.11.2017 / 00:41