Avatar of stummj
Flag 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 http://www.mypage.com/page5.htm they get redirected to http://www.mypage.com, 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 undefined
Last Comment

8/22/2022 - Mon
R. Andrew Koffron

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

Hi - thanks.. it needs to be done by HTML (for technical reasons!)
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

paste this in your <head>

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">

Open in new window

Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Scott Fell

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(window.location.search);
  if(results == null)
    return "";
    return decodeURIComponent(results[1].replace(/\+/g, " "));
var pass = getParameterByName('pass');

if (pass !== "xyz") {
    window.location = "http://myhomepage.com";

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.

All good stuff - I will try them (well not the server side stuff - thanks for these but I think I was clear!)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.