Link to home
Start Free TrialLog in
Avatar of stummj
stummjFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Web Page Redirect

Is there anyway  of forcing a user to my web homepage if they link to a lower level.

i.e. if they go directly to they get redirected to, and can only get to page 5 from the links on the homepage?

So if they click the link to page 5 then they go to it, but if they try to get to it any other way they get sent to the homepage first.
Avatar of R. Andrew Koffron
R. Andrew Koffron
Flag of United States of America image

I'm not a web developer at all, but a lot of php/asp and also a lot of css pages all load in a single page and change the content so it's close to what it sounds like, you want to do.

again I'm not a web developer but my knee jerk reaction is it'd take more work to set parameters and script the page to check the referring page, than to just make a dynamic first page.
if your using apache you can make a .htaccess file and paste this inside of it

<IfModule mod_rewrite.c>

	RewriteEngine On
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteRule ^(.*)$ index.php [QSA,L]


Open in new window

just replace index.php with the file and/or directory you want the user directed too
and you must also make sure you have mod_rewrite enabled inside your httpconfig in apache
Avatar of stummj


Hi - thanks.. it needs to be done by HTML (for technical reasons!)
paste this in your <head>

<meta HTTP-EQUIV="REFRESH" content="0; url=">

Open in new window

Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I agree with DaveBaldwin, you should really  use a serverside script.  In asp it could be something as simple as below where you either create a form with a variable called pass or with a link that has the querystring pass=xyz.  The actual link code would be something like

<a href="page5.asp?pass=xyz">page5.asp </a>
Then on the page5.asp you would insert the code below.  You can do almost the identical thing in php too.
if request("pass")<>"xyz" then
end if

Open in new window

If you can not use a server side script you can do duplicate the above code by placing the script  below in your head section and in your home page use the link <a href="page5.html?pass=xyz">page5.html </a>
function getParameterByName(name)
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(;
  if(results == null)
    return "";
    return decodeURIComponent(results[1].replace(/\+/g, " "));
var pass = getParameterByName('pass');

if (pass !== "xyz") {
    window.location = "";

Open in new window

In both examples, if the link does not have the querystring pass=xyz, then it will send the user back to your home page.
Avatar of stummj


All good stuff - I will try them (well not the server side stuff - thanks for these but I think I was clear!)