qwerty
qwerty

Reputation: 105

Redirect to all html page and folders to index.html

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:

  1. User click to link: mydomain.com/blabla (normally goes to 404)
  2. Web site redirect to user mydomain.com/index.html or mydomain.com/index.html?par=blabla
  3. in 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

Answers (1)

Polostor
Polostor

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

  1. R stands for redirect with response code 301
  2. L means it is last rule

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

Related Questions