How to redirect a single web page other than using htaccess

How to redirect a single web page other than using htaccess - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the How to redirect a single web page other than using htaccess error on your web browser. Problem :


I'd like to redirect a single web page, it will be a temporary redirect so I don't want it to affect SEO rankings.



So I was thinking of using a method other than htaccess, but if it would be more efficient to use htaccess please let me know.



Also, is it possible to redirect the homepage to another page but have all other pages un-redirected?



So for e.g. www.abc.com redirected to www.example.com



But



www.abc.com/news.html is not affected.



For w3d:



I'm trying to do this:



# Use PHP5.4 as default
RewriteEngine On
RewriteRule ^news1.html$ https://www.example.com/news1.html [R,L]
RewriteRule ^news2.html$ https://www.example.com/news2.html [R,L]
RewriteRule ^news3.html$ https://www.example.com/news3.html [R,L]


Options -Indexes


even tried this:



Redirect 302 /news1.html example.com/news1.html
Redirect 302 /news2.html example.com/news2.html


only the first one gets redirected.



Also do they both execute exactly the same function?


Solution :


...if it would be more efficient to use htaccess



If you have access to .htaccess then there doesn't seem any reason not to use this. Note that this is a "302 Temporary", not a "301 Permanent" redirect as you had initially tagged in the question.


To redirect just the home page to example.com (an external domain) in .htaccess using mod_rewrite:


RewriteEngine On

RewriteRule ^(index.html)?$ https://example.com/ [R,L]

If both the source and target domains point to the same place then you'll need to check the requested hostname in a preceding condition. For example:


RewriteCond %HTTP_HOST =sourcedomain.example
RewriteRule ^(index.html)?$ https://example.com/ [R,L]

This redirects when there is no path on the URL (ie. the home page), or index.html only. The R flag on its own indicates a temporary redirect, although you can be explicit and write R=302, but it's the same.


^(index.html)?$ - This is a regular expression. This is the "pattern" used to match the requested URL. Only if the URL matches the pattern will the redirect occur. ^ and $ are anchors indicating the start and end of the string/URL. ? makes the preceding item optional (in this case the parenthesised sub pattern index.html is made optional). The . (dot) needs to be backslash escaped (ie. .) in order to match a literal dot, otherwise it is a special/meta character meaning any character.


Other ways to redirect... JavaScript or META refresh (although that might be perceived as permanent these days I'm not sure - it apparently does pass "link juice" so will affect SEO). The .htaccess method is the preferred method. It is more flexible, the most reliable and arguably less convoluted.



If you want to redirect a single page, you have options.



The oldest way which may still work, but might be the worst way from SEO point of view is to create an HTML file containing the following:



<html>
<head>
<title>Redirect</title>
<meta http-equiv="REFRESH" content="1;URL=http://www.newsite.com">
</head>
<body>
<!-- add website code here -->
</body>
</html>


The above causes a redirect after 1 second. you can change 1; to 0; after "content" to refresh instantly but that might work with only certain browsers.



A little better way if you have a php enabled server is to create index.php with the following contents:



<?php
header("HTTP/1.1 301 Redirect",true);
header("Location: http://www.newsite.com",true);
?>
<html>
<head>
<title>Redirect</title>
</head>
<body>
Go <a href="http://www.newsite.com">here</a> for the document.
</body>
</html>


You may also follow above posters advice for a redirect, but if you want slightly faster performance, then instead of placing the rules in an .htaccess in the folder, you can add the following to apache's main configuration file (usually httpd.conf) so that apache doesn't have to constantly search many subfolders for the rules:



<directory /path/to/htaccessfile>
#insert rewrite rules here
</directory>


Only thing is that you need high enough access to the server (shell access preferred) and then apache will need to be restarted after this change.


We hope that this article has helped you resolve the htaccess, redirects, 302-redirect error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=