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
-
301 Redirects from example.com to store.example.com and then removing store.example.com subdomain
Hi I'm trying to wrap my head around the best approach for migrating our website. We're migrating from our example.com (joomla) site to our existing store.example.com (shopify) site... with the plan to finish the redirects/migration then remove the subdomain from shopify and use example.com moving forward. I've never done this and asking here to see if any harm will come from re-directing example.com URLs to store.example.com URL's then changing the store.example.com URL's to example.com. Right now my plan would run like this: redirect example.com URL's to store.example.com remove subdomain on store.example.com use example.com moving forward. wonder what happens next? Is there going to be any issues here, possible harm to the URL's?
Technical SEO | | Minarets0 -
When to re-write and redirect a blog url?
What are best practices for rewriting (and then redirecting) blog URLs? I refresh old blog posts on our blog every month and many of them have URLs that are too long or could be improved. However, many of them also already get decent organic traffic and I don't want to lose traffic due to a URL redirect. Are there any best practices or "rules" I can follow when deciding whether to re-write and redirect blog URLs?
Content Development | | Emily.R.Monrovia
Thanks!0 -
How to sunset language subdomains that we don't want to support anymore?
We have a primary domain www.postermywall.com. We have used subdomains for offering the same site in different languages, like es.postermywall.com, fr.postermywall.com etc. There are certain language subdomains that have low traffic and are expensive to get translated. We have decided to sunset 3 subdomains that match that criteria. What is the best way of going about removing those subdomains? Should we just redirect from those subdomains to www.postermywall.com? Would that have any negative impact on our primary domain in Google's eye etc.? Anything other than a redirect that we should be considering?
Technical SEO | | 250mils0 -
Can we use internal no-follow links without negatively affecting rankings
we are creating a site structure for a travel website. the site homepage has a top navigation bar with 8 top level links and a total link count of 33 links in this (within menus). There are also 10 footer and ad-hoc links As this top navigation bar is a site-wide navigation, when entering s specific "travel destination" page, the "travel destination" page has its own contextual links and reference links, making the total inks on the destination page approx 107. do you think its ok to make all links in the top navigation bar no follow on all pages except the homepage? how would you approach this to create less links to maintain effective link-juice flow to required pages
On-Page Optimization | | Direct_Ram0 -
Should old pages that have being 301 redirected but have no/mimimal traffic be deleted?
In other words, I have pages from years ago that are redirected but how can I tell if traffic still flows through them? And if there is no or minimal traffic should the 301 be deleted? Linck
On-Page Optimization | | LinckB0 -
What is the best way to execute a geo redirect?
Based on what I've read, it seems like everyone agrees an IP-based, server side redirect is fine for SEO if you have content that is "geo" in nature. What I don't understand is how to actually do this. It seems like after a bit of research there are 3 options: You can do a 301 which it seems like most sites do, but that basically means if google crawls you in different US areas (which it may or may not) it essentially thinks you have multiple homepages. Does google only crawl from SF-based IPs? 302 passes no juice, so probably don't want to do that. Yelp does a 303 redirect, which it seems like nobody else does, but Yelp is obviously very SEO-savvy. Is this perhaps a better way that solves for the above issues? Thoughts on what is best approach here?
On-Page Optimization | | jcgoodrich0 -
Appropriate Use of Rel Canonical
I have encountered problems regarding rel canonical. When I ran On-Page Report Card it says **Error: ** Appropriate Use of Rel Canonical Canonical URL: "http://www.sourcedental.createmyid.net/teeth-whitening/" Explanation: If the canonical tag is pointing to a different URL, engines will not count this page as the reference resource and thus, it won't have an opportunity to rank. Make sure you're targeting the right page (if this isn't it, you can reset the target above) and then change the canonical tag to reference that URL. Recommendation We check to make sure that IF you use canonical URL tags, it points to the right page. If the canonical tag points to a different URL, engines will not count this page as the reference resource and thus, it won't have an opportunity to rank. If you've not made this page the rel=canonical target, change the reference to this URL. NOTE: For pages not employing canonical URL tags, this factor does not apply." I just don't know how to fix this. I am using Wordpress SEO by Yoast but I haven't change any settings regarding rel canonical. Can anyone help me with this? Thanks
On-Page Optimization | | projectassistant0 -
How different does each page tilte need to be?
I've got a site that is all about wood countertops. There are a few ways people can find info on wood tops. (main) wood countertops (main) butcher block butcher block counters wood counters hardwood countertops etc. For the most part I want to rank for the two top key phrases because they pretty much cover all the other basis with google being as smart as it is. So they question is how different should each page title be? Examples: Wood Countertops - Butcher Block Counters | by J. Aaron = index page Wood Counter tops - Butcher Block Counters - About Us | J. Aaron = about us page Cleaning Butcher Block - Wood Countertop Maintenance | J. Aaron = care & maintenance page Would it be OK to use: <title>Wood Countertops - Butcher Block Counters | by J. Aaron</title> as the template for the whole site with the addition of the actual page subject as an additional piece of the sentence, like example 2 or would that be too similar? Also is that a good idea or should I commit to optimizing each page for a different key phrase? If so would you optimize the home page for the most searched for phrase and let the other pages back it up with the other search terms?
On-Page Optimization | | JAARON0