How do I carry out a redirect? Is there a code I need to use?
-
How do I carry out a redirect? Is there a code I need to use? Thank you in advance.
-
@meltingpointgoat maybe I can recommend the following for whats its worth,
I’ve been diving deep into SEO recently and found a bunch of tools that have been super helpful for different aspects of my workflow. Thought I’d share a few in case you find them useful!
https://ralfvanveen.com/en/tools/domain-age-checker/
https://ralfvanveen.com/en/tools/domain-authority-checker/
https://ralfvanveen.com/en/tools/seo-impact-calculator/
https://ralfvanveen.com/en/tools/content-length-vs-ranking-calculator/
https://ralfvanveen.com/en/tools/content-security-policy-csp-checker/
https://ralfvanveen.com/en/tools/backlink-outreach-email-generator/
https://ralfvanveen.com/en/tools/fetch-and-render/
https://ralfvanveen.com/en/tools/bulk-pagespeed-checker/
https://ralfvanveen.com/en/tools/bulk-amp-validator/
https://ralfvanveen.com/en/tools/xml-sitemap-checker/
https://ralfvanveen.com/en/tools/schema-markup-generator/I’ve found these tools over at https://ralfvanveen.com/en/tools/. Thought they were worth sharing!
Are you using similar tools? Would love to know what’s been working for you lately.
Please let me know, I am regularly looking for new ways to optimize my SEO strategies.Regards,
Ulrich
-
Hi!
nice comment -
Redirecting sounds simple, but it can be a lot of work, especially for SEO. You need to carefully map old URLs to new ones, or you risk losing traffic. Big companies often have dedicated teams managing this to ensure everything’s smooth. Implementing strategies like resource smoothing helps here - spreading out tasks over time so no one is overwhelmed and SEO remains on point (see here).
For example, you could have one team member focus on identifying which URLs need redirecting while another handles updating the code over a week, instead of doing everything at once. This way, the workload stays manageable, and there’s less risk of making mistakes.
When implementing redirects, always check for broken links and monitor the changes to ensure traffic isn’t dropping. And remember, a good redirect strategy is essential for maintaining SEO, so take your time and do it right to avoid losing valuable rankings.
-
To carry out a redirect, you can use the following code depending on the language or platform you're working with.
In HTML (meta tag redirect):<meta http-equiv="refresh" content="0; url=https://new-url.com">
In JavaScript:
window.location.href = "https://new-url.com";
In PHP:
header("Location: https://new-url.com"); exit();
Choose the appropriate method based on your environment.
Thanks!
JHK Infotech -
@laurentjb ... Depend on your goals, if you are using cloudflare, you can go to page rules and create 301 / 302 redirect easily
-
Depend on your goals, if you are using cloudflare, you can go to page rules and create 301 / 302 redirect easily
-
@laurentjb said in How do I carry out a redirect? Is there a code I need to use?:
How do I carry out a redirect? Is there a code I need to use? Thank you in advance.
To carry out a redirect, you typically use a piece of code specific to the platform you're working on. For example, in HTML, you can use<meta http-equiv="refresh" content="0;url=http://example.com">
. If you’re using server-side code, such as PHP, you can useheader("Location: http://example.com");
. Just like how you might tweak a Wendy’s Taco Salad recipe to fit your taste, adjusting redirect code ensures your users are sent to the right place. i have wendy's taco salads related site and same done for that website too -
If you are using free CloudFlare DNS and SSL, you can create 301 redirection easily with their tools.
-
Yes, i have done many site like Digitech Journals. To carry out a redirect, you need to use specific code depending on the type of redirect and the server environment you’re working with. The most common types of redirects are 301 (permanent) and 302 (temporary) redirects.
1. Using
.htaccess
(Apache Server)If your website is hosted on an Apache server, you can use the
.htaccess
file to create redirects.a. 301 Permanent Redirect:
Redirect 301 /old-page.html https://www.example.com/new-page.html
- Explanation: This code permanently redirects
old-page.html
tonew-page.html
.
b. 302 Temporary Redirect:
Redirect 302 /old-page.html https://www.example.com/new-page.html
- Explanation: This code temporarily redirects
old-page.html
tonew-page.html
.
c. Redirecting an Entire Domain:
Redirect 301 / https://www.newdomain.com/
- Explanation: This code permanently redirects all pages from the old domain to the new domain.
2. Using PHP for Redirects
If you have access to your website’s PHP code, you can use the following PHP code for redirects.
a. 301 Permanent Redirect:
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: https://www.example.com/new-page.html"); exit(); ?>
- Explanation: This PHP code permanently redirects to
new-page.html
.
b. 302 Temporary Redirect:
<?php header("Location: https://www.example.com/new-page.html"); exit(); ?>
- Explanation: This PHP code temporarily redirects to
new-page.html
.
3. Using JavaScript (Client-Side Redirect)
You can use JavaScript for client-side redirects, though it's generally better to use server-side redirects for SEO purposes.
a. JavaScript Redirect:
<script type="text/javascript"> window.location.href = "https://www.example.com/new-page.html"; </script>
- Explanation: This script redirects the user to
new-page.html
.
4. Using Nginx
If your website is hosted on an Nginx server, you can set up redirects in the Nginx configuration file.
a. 301 Permanent Redirect:
server { listen 80; server_name www.example.com; return 301 https://www.example.com$request_uri; }
- Explanation: This code redirects all HTTP traffic to HTTPS with a permanent redirect.
b. Redirecting a Single Page:
location /old-page.html { return 301 https://www.example.com/new-page.html; }
- Explanation: This code permanently redirects
old-page.html
tonew-page.html
.
5. HTML Meta Refresh (Not Recommended for SEO)
You can use a meta refresh tag in the HTML
<head>
section, but it's not ideal for SEO as it's not a true redirect.<meta http-equiv="refresh" content="0; url=https://www.example.com/new-page.html">
- Explanation: This code redirects after 0 seconds to
new-page.html
.
Choosing the Right Redirect
- 301 Redirect: Use when you want to permanently move a page or domain. This tells search engines to pass the SEO value from the old URL to the new one.
- 302 Redirect: Use when the move is temporary, and you plan to revert to the old URL.
Always test your redirects after implementation to ensure they work correctly and that search engines and users are directed to the intended destination.
- Explanation: This code permanently redirects
-
Complete redirection process requires using 301 redirection
You can redirect your old domain to the new one via Cloudflare or by contacting your hosting manager -
It depends on which type of redirect you mean and what the purpose is. Here are two common scenarios:
For redirecting a single page:
You can use a 301 redirect in your .htaccess file (for Apache servers):Redirect 301 /old-page.html https://www.yoursite.com/new-page.html
For redirecting an entire domain:
To redirect all pages from an old domain to a new one, you can use this code in your .htaccess file:RewriteEngine On RewriteCond %{HTTP_HOST} ^olddomain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.olddomain.com [NC] RewriteRule ^(.*)$ https://www.newdomain.com/$1 [L,R=301,NC]
Both methods use 301 (permanent) redirects, which is typically best for SEO. Always test your redirects thoroughly to ensure they work as intended across your site.
-
@laurentjb said in How do I carry out a redirect? Is there a code I need to use?:
How do I carry out a redirect? Is there a code I need to use?
To carry out a redirect, you typically need to use specific code or configurations depending on the type of redirect you want to implement and the server or platform you're working with. The most common types of redirects are 301 (permanent) and 302 (temporary).
But I Recommend you Use Plugins
The Best WP Plugin is ( Redirection )You can use plugins like Redirection or Yoast SEO to manage redirects without needing to write code.
301 Redirect: Use when the original page has permanently moved to a new URL.
302 Redirect: Use when the move is temporary. -
@laurentjb are you talking about domain redirection ?
-
@laurentjb Yes you can redirect 1 page to another using any redirection plugin.
You can either 301(Moved Permanently) or 302(Moved Temporary) the Url 1 to Url 2 -
@laurentjb said in How do I carry out a redirect? Is there a code I need to use?:
How do I carry out a redirect? Is there a code I need to use? Thank you in advance.
To set up a redirect, you typically need to use some code depending on your server environment. For example, if you’re using Apache, you can add a redirect rule to your .htaccess file. Here’s a basic example of a 301 redirect in an .htaccess file:
apache
Redirect 301 /old-page.html http://www.yoursite.com/new-page.html
If you're using Nginx, you would add a redirect rule to your server configuration file like this:
nginx
location /old-page {
return 301 http://www.yoursite.com/new-page;
}For WordPress or other CMSs, there are plugins available that can help you manage redirects without needing to handle code directly.
I hope this helps! Let me know if you have any more questions. because te same issue a=occure with my site then i resolve it by using this method.
Thank you!
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Unsolved I have a "click rate juice" question would like to know.
Hello I have a "click rate juice" question would like to know. For example. I created a noindex site for a few days event purposes. Using a random domain like this: event.example.com. Expecting 5000+ clicks per day. Is it possible to gain some traffic juice from this event website domain "example.com" to my other main site "main.com" but without exposing its URL. Thought about using 301 redirecting "example.com" to "main.com". But it will reveal the example-b.com to the general public if someone visits the domain "example.com". Also thought about using a canonical URL, but it would not be working because the event site is noindex. or it would not matter at all 🤔 Wondering if there is a thing like this to gain some traffic juice for another domain? Thanks
Intermediate & Advanced SEO | | Blueli0 -
Multilang site: Auto redirect 301 or 302?
We need to establish if 301 or 302 response code is to be used for our auto redirects based on Accept-Language header. https://domain.com
International SEO | | fJ66doneOIdDpj
30x > https://domain.com/en
30x > https://domain.com/ru
30x > https://domain.com/de The site architecture is set up with proper inline HREFLANG.
We have read different opinions about this, Ahrefs says 302 is the correct one:
https://ahrefs.com/blog/301-vs-302-redirects/
302 redirect:
"You want to redirect users to the right version of the site for them (based on location/language)." You could argue that the root redirect is never permanent as it varies based on user language settings (302)
On the other hand, the lang specific redirects are permanent per language: IF Accept-Language header = en
https://domain.com > 301 > https://domain.com/en
IF Accept-Language header = ru
https://domain.com > 301 > https://domain.com/ru So each of these is 'permanent'. So which is the correct?0 -
Combining products - edit existing product page or 301 redirect to new page?
We want to combine existing products - e.g. 'hand lotion' and 'body lotion' will become 'hand & body lotion'. As such, we'll need to combine the two product pages into one. What would be the best route to take in terms of SEO to do this? My initial reaction is to create a new product page and then 301 or 302 redirect the old products to the new product page depending on if the change is permanent or temporary. Would you agree? Or am I missing something?
On-Page Optimization | | SwankyApple1 -
How to 301 redirect, without access to .htaccess and to a new domain
There are few ways to do this and I would like to ask other Mozzers if they have found the best way. We have a site .co.uk and are moving it back to .com. However we do not have any access to the site folders for .co.uk. (We have to move it anyway as our provider is withdrawing their service). We have built our URL 301 redirect file and it is ready to go, but how to impliment it? We can repoint .co.uk to another site, and then redirect all traffic for each URL but this is quite messy, or just forget trying to 301 each page and just rediect the whole site.
On-Page Optimization | | BruceA
the .com has more authority already, but we ready do not want to frustrate visitors who are using a link to reach a product, only to find they hit our homepage and not the product. Your thoughts would be very welcome or other ideas Bruce0 -
Reverse 301 redirect - how will that work?
Hi We have done some testing where we have changed our URL to a new name and 301 redirected the old to the new. It has now been decided to go back to the old url again but is there an seo risk to this? Will all the inbound links that as redirected in the first change be lost or?
On-Page Optimization | | AndersDK0 -
What font should i use for my text to make page better
Hi i have changed a page layout and first of all would like to know what people think, also i would like to know what font i should be using to make the page better. My website is www.in2town.co.uk any help would be great
On-Page Optimization | | ClaireH-1848860 -
Using a more relevant brand title for blog
I'm a newbee here so I appologize in advance for asking a question that might already be aswered ( i looked I promise). The question is this, I've been fiddling with the title tags and came upon the need to make a decision about separating our blog brand to be more specific to it's content. We're a moving company, our primary website talks about services and is branded with our name (%page_name% | 2 Brothers Moving & Delivery Portland Oregon), our blog is a work in progress "Moving Guide" (%post_title% | Portland Moving Guide). Should I stick with the standard brand name on the blog or call it something keyword specific like above? As a side question what do you all think about my titles in the first place? In case you'd like to take a look: www.2brothersmoving.net www.2brothersmoving.net/blog
On-Page Optimization | | r1200gsa0 -
Which method should I use for my URL structure?
I have an existing site that is currently utilizing a structure that is like this: http://www.mysite.com/Ohio/City-of-Cleveland-PRODUCT-NAME Should I restructure it like: http://www.mysite.com/Ohio/City-of-Cleveland/Product-Name We are doing very well with very specific searches already but are sometimes coming in 2nd and 3rd place. For example: If I search for CLEVELAND PRODUCT NAME I always come up in the top three and about 60% of the time I am #1. I want to make it better. We have only launched in 4 states but plan on launching an additional 4 states over the next few weeks and I want to make sure we are building things properly. Any feedback would be wonderful. As usual, thanks everyone!! -Alex
On-Page Optimization | | dbuckles0