Reputation: 105
How do I redirect all folders to my index.html and determine where users came from.
Firstly I have only index.html
and .htaccess
files.
Scenario:
mydomain.com/blabla
(normally goes to 404)mydomain.com/index.html
or mydomain.com/index.html?par=blabla
mydomain.com/index.html
show alert "came from mydomain.com/blabla
"Is this possible? Thanks.
UPDATE**********
I found solve like this.
Firstly changed .htaccess file: https://stackoverflow.com/a/21663207/1173413
and use alert(window.location);
as Polostor's said.
Upvotes: 3
Views: 1549
Reputation: 187
I can imagine something like this.
File .htaccess to redirect the page and set the last page as getter. When .htaccess is in main folder it works for any subfolder.
RewriteEngine on
RewriteRule ^(.*) /index.html?page=$1 [R=301,L]
Edit: better solution should be https://stackoverflow.com/a/12500251/4745695
Rules are
And in index.html it would be something like.
<html>
<head>
<title>My title</title>
<script>
alert(window.location.search.substring(1));
</script>
</head>
<body>
</body>
</html>
I took get method from How to get the value from the GET parameters? ( location.search in javascript respectively ) and .htaccess is well described on those pages http://www.jakpsatweb.cz/server/ (in Czech, to translate them use google translator).
Upvotes: 1