简体   繁体   中英

How to correct redirect to any url from within a HTML page?

Of course I know how to redirect from within a HTML to any url like

<meta http-equiv="refresh" content="0; url=http://example.com/" />

or

<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="1; url=http://example.com">
        <script type="text/javascript">
            window.location.href = "http://example.com"
        </script>
        <title>Page Redirection</title>
    </head>
    <body>
        <!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->
        If you are not redirected automatically, follow this <a href='http://example.com'>link to example</a>.
    </body>
</html>

But what I wanted to know is, is this the correct way how to do it when trying to redirect like bit.ly is doing. What the purpose of my question?

I have many static urls for several services like Skype for Business Meeting, GoToMeeting, HRS Hotel Reservation, other Booking pages etc. Where all have any Id/Tag within the Url which needs to correctly typed in to get to the correct service. For example at Skype Meeting I am providing this url to my colleagues/customers. What I want to do is to have some static.html on my domain like

www.my.dom/skype

and give this url to my customer, so that it is easy to remember and to type.

Therefore my question is:

Is this the correct way to having a static redirect url maybe without getting blocked by AntiVirus Software, Browsers Security Checks etc. Cause I don't want that the users receive any error message during redirection.

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} (^|&)title=abc(&|$) [NC]
RewriteRule ^a/b/(.*)$ http://www.example.com/xyz/? [L,R=302,NC]

Remember RewriteRule doesn't match leading slash.

Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

You could also use a 303 status code. The advantage is that it would work for POST requests as well:

https://en.wikipedia.org/wiki/HTTP_303

Request:

POST / HTTP/1.1
Host: www.example.com

Response:

HTTP/1.1 303 See Other
Location: http://example.org/other

Regarding "what is the correct way": any one that suits your needs. The very existence of HTML tags/attributes shows it is correct, as is the server response code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM