stummj
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.
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.
if your using apache you can make a .htaccess file and paste this inside of it
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
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
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
ASKER
Hi - thanks.. it needs to be done by HTML (for technical reasons!)
paste this in your <head>
<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
>page5.htm l </a>
<a href="page5.asp?pass=xyz">
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
resposne.redirect("index.asp")
end if
%>
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"<script>
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 "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
var pass = getParameterByName('pass');
//alert(pass)
if (pass !== "xyz") {
window.location = "http://myhomepage.com";
}
</script>
In both examples, if the link does not have the querystring pass=xyz, then it will send the user back to your home page.
ASKER
All good stuff - I will try them (well not the server side stuff - thanks for these but I think I was clear!)
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.