Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way for a HTML page to redirect to a script

I am looking for fast methods/ways I can redirect a HTML page to another page.

Currently I use meta-tags to redirect a HTML page to a python script that grabs the website HTML from a SQL database(grabs different HTML based on whether user is on a Mobile device) then sends that HTML back. But this is visibly slow, it shows a blank white page(redirect HTML page) then shows the python script page.

I know that its not the python script thats slow because if I just go straight to the python script(no redirect from the HTML page) then it loads very fast & with no white screen.

So for example; someone accesses http://mywebsite.com/contactUs.html which contains only the following HTML:

<HTML> <HEAD><META HTTP-EQUIV=Refresh CONTENT="0; url=cgi-bin/loadWebPage.py?webpage=50002">  </HEAD> </HTML> 
<!-- This redirects to my python script that grabs the contact us HTML & prints it out(shows the webpage HTML) -->

Are there other ways a HTML file can redirect to a python script that will be faster?

Maybe I can use HTTP messages? Would the following text/code work in a HTML file?:

Status: 301 Moved"
Location:/cgi-bin/loadWebPage.py?webpage=50002

Would my last resort be AJAX or javascript to get the fastest result?

<html>
<head>

    <script type="text/javascript">
    <!--
        window.location = 'http://mywebsite.com/cgi-bin/loadWebpage.py?webPage=50001';
    -->
    </script>
</head>
<body>

</body>
</html>
like image 451
Georman Avatar asked Aug 29 '11 02:08

Georman


People also ask

How do I instantly redirect in HTML?

The simplest way to redirect to another URL is to use an HTML <meta> tag with the http-equiv parameter set to “refresh”. The content attribute sets the delay before the browser redirects the user to the new web page. To redirect immediately, set this parameter to “0” seconds for the content attribute.

How do I automatically redirect in HTML?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

How do I redirect a HTML page after few seconds?

Complete HTML/CSS Course 2022 To redirect URL to a different website after few seconds, use the META tag, with the content attribute. The attributes set the seconds.

How do I automatically redirect?

Complete HTML/CSS Course 2022 It happens due to page redirection. To redirect from an HTML page, use the META Tag. With this, use the http-equiv attribute to provide an HTTP header for the value of the content attribute. The value of the content is the number of seconds; you want the page to redirect after.


2 Answers

Place a file called .htaccess in the same directory as your HTML file. If the file is called "http://www.example.com/foo/bar.html" then .htaccess would contain:

Redirect permanent /foo/bar.html http://www.example.com/script.py

Note that the file that gets redirected does not have http://www.example.com, while the file you redirect it to needs the full URL.

If it's your own server, it's a little faster to disable .htaccess files, while instead putting the Redirect command in your httpd.conf file.

like image 130
Mike Crawford Avatar answered Sep 19 '22 19:09

Mike Crawford


Don Quixote is correct about the .htaccess, I would just like to point out that

http://progtuts.info/198/the-anatomy-of-a-htaccess-file-hints-and-tips/

Will provide some examples and a whole lot of stuff on how to edit your htaccess files etc.

Redirect will definitely work.

like image 37
Singular1ty Avatar answered Sep 18 '22 19:09

Singular1ty