: How to redirect a single web page other than using htaccess 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
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. abc.com redirected to example.com
But
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$ www.example.com/news1.html [R,L]
RewriteRule ^news2.html$ www.example.com/news2.html [R,L]
RewriteRule ^news3.html$ 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?
More posts by @Mendez628
2 Comments
Sorted by latest first Latest Oldest Best
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: 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.
...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 in .htaccess using mod_rewrite:
RewriteEngine On
RewriteRule ^(index.html)?$ example.com [R,L]
This redirects when there is no path on the URL (ie. the home page), or index.html. 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.