Moz Q&A is closed.
After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.
Php 301 redirect
- 
					
					
					
					
 Hi I am migrating an old wordpress site to a custom PHP site and the URL profiles will be different, so want to retain all link profiles and more importantly if a user visits the old urls via search then they are seamlessly transferred to the new equivalent page For example www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php etc What is the best way of achieving this apart from .htaccess as not 100% confident of doing this. Could it be done via PHP or using meta tags? 
- 
					
					
					
					
 Hi, Not meta tags. If no other way, You should do it with PHP header() function. <code>header("HTTP/1.1 301 Moved Permanently"); header("Location: /somelocation");</code>But you need to add some conditions to determine if the page should be redirected. For example to redirect /example.html to https://www.new-domain.com/example you need to write something like: if (isset($_SERVER['REQUEST_URI']) && parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) == '/example.html') {header('HTTP/1.1 301 Moved Permanently');header('Location: https://www.new-domain.com/example');exit();} It can be a lot of code, if you need to redirect many pages. In this case, You can try to use PHP 301 Redirect Generator - https://www.301-redirect.online/php-header-location-generator 
- 
					
					
					
					
 OK - take this page: www.domain.com/about-us Presuming that this is a php page, open it up in an editor and insert this code right at the top 
 Header( "HTTP/1.1 301 Moved Permanently" );
 Header( "Location: http://www.domain.com/aboutus.php" );
 ?>and repeat this same procedure for any other files you need to redirect. 
- 
					
					
					
					
 Hi Thanks for the link, it mentions under php Header( "HTTP/1.1 301 Moved Permanently" ); 
 Header( "Location: http://www.new-url.com" );
 ?>So how would I implement multiple page changes in the code above i.e. www.domain.com/about-us is going to need to redirect to www.domain.com/aboutus.php 
 www.domain.com/furniture is going to need to redirect to www.domain.com/furniture-collections.php
- 
					
					
					
					
 There are various ways of doing this and yes the good ol htaccess can be a bit daunting at first. Check this page out, should help you. 
 http://www.webconfs.com/how-to-redirect-a-webpage.phpYou cannot do a 301 redirect with meta tags - a meta tag "refresh" does not provide a 301 redirect. Useful hint: Before commiting to it, try using the same script either in PHP or HTACCESS but with a 302 (temporary redirect) - then test it works and then make it a 301 (permanent redirect) - that way if you get it wrong, Google will not take the permanent instruction. 
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 ToolsChat with the community about the Moz tools. 
- 
		
		SEO TacticsDiscuss the SEO process with fellow marketers 
- 
		
		CommunityDiscuss industry events, jobs, and news! 
- 
		
		Digital MarketingChat about tactics outside of SEO 
- 
		
		Research & TrendsDive into research and trends in the search industry. 
- 
		
		SupportConnect on product support and feature requests. 
Related Questions
- 
		
		
		
		
		
		301 Redirects for Multiple Language Sites in htaccess File
 Hi everyone, I have a site on a subdomain that has multiple languages set up at the domain level: https://mysite.site.com, https://mysite.site.fr , https://mysite.site.es , https://mysite.site.de , etc. We are migrating to a new subdomain and I am trying to create 301 redirects within the htaccess file, but I am a bit lost on how to do this as it seems you have to go from a relative url to an absolute - which would be fine if I was only doing this for the english site, but I'm not. It doesn't seem like I can go from absolute url to an absolute url - but I could be wrong. I am new to editing the htaccess file - so I could definitely use some advice here. Thanks. Intermediate & Advanced SEO | | amberprata0
- 
		
		
		
		
		
		We are redirecting http and non www versions of our website. Should all versions http (non www version and www version) and https (non www version) should just have 1 redirect to the https www version?
 We are redirecting http and non www versions of our website. Should all versions http (non www version and www version) and https (non www version) should just have 1 redirect to the https www version? Thant way all forms of the website are pointing to one version? Intermediate & Advanced SEO | | Caffeine_Marketing0
- 
		
		
		
		
		
		Google Is Indexing my 301 Redirects to Other sites
 Long story but now i have a few links from my site 301 redirecting to youtube videos or eCommerce stores. They carry a considerable amount of traffic that i benefit from so i can't take them down, and that traffic is people from other websites, so basically i have backlinks from places that i don't own, to my redirect urls (Ex. http://example.com/redirect) My problem is that google is indexing them and doesn't let them go, i have tried blocking that url from robots.txt but google is still indexing it uncrawled, i have also tried allowing google to crawl it and adding noindex from robots.txt, i have tried removing it from GWT but it pops back again after a few days. Any ideas? Thanks! Intermediate & Advanced SEO | | cuarto7150
- 
		
		
		
		
		
		Default Wordpress 301 Redirects of JS and CSS files. Bad for SEO & How to Fix?
 Hi there: We are developers with some digital marketing expertise, but a current issue has us perplexed. An outside SEO firm has asked us to clean up a large number of 301 redirects. Most of these are 'default' Wordpress behavior that relate to calling the latest version of a JS or CSS file. For instance, a JS file is called with this: https://websitexyz.com/wp-includes/js/wp-embed.min.js?ver=4.9.1 but ultimately redirects to this: https://websitexyz.com/wp-includes/js/wp-embed.min.js. We are being asked to prevent the redirect from happening by, presumably, calling the ultimate file to begin with. The issue is that, as far as we know, there's no easy way to alter WP behavior to call the ultimate file to begin with. Does anyone have any thoughts on this? Thanks. Intermediate & Advanced SEO | | Daaveey0
- 
		
		
		
		
		
		Will 301 Redirects Slow Page Speed?
 We have a lot of subdomains that we are switching to subfolders and need to 301 redirect all the pages from those subdomains to the new URL. We have over 1000 that need to be implemented. So, will 301 redirects slow the page speed regardless of which URL the user comes through? Or, as the old urls are dropped from Google's index and bypassed as the new URLs take over in the SERPs, will those redirects then have no effect on page speed? Trying to find a clear answer to this and have yet to find a good answer Intermediate & Advanced SEO | | MJTrevens0
- 
		
		
		
		
		
		Problem with redirects in coldfusion
 How to redirect pages in cold fusion? If using ColdFusion and modrewrite, the URL will never be redirected from ModRewrite. Intermediate & Advanced SEO | | alexkatalkin0
- 
		
		
		
		
		
		Should I redirect my xml sitemap?
 Hi Mozzers, We have recently rebranded with a new company name, and of course this necessitated us to relaunch our entire website onto a new domain. I watched the Moz video on how they changed domain, copying what they did pretty much to the letter. (Thank you, Moz for sharing this with the community!) It has gone incredibly smoothly. I told all my bosses that we may see a 40% reduction in traffic / conversions in the short term. In the event (and its still very early days) we have in fact seen a 15% increase in traffic and our new website is converting better than before so an all-round success! I was just wondering if you thought I should redirect my XML sitemap as well? So far I haven't, but despite us doing the change of address thing in webmaster tools, I can see Google processed the old sitemap xml after we did the change of address etc. What do you think? I know we've been very lucky with the outcome of this rebrand but I don't want to rest on my laurels or get tripped up later down the line. Thanks everyone! Amelia Intermediate & Advanced SEO | | CommT0
- 
		
		
		
		
		
		Can an incorrect 301 redirect or .htaccess code cause 500 errors?
 Google Webmaster Tools is showing the following message: _Googlebot couldn't access the contents of this URL because the server had an internal error when trying to process the request. These errors tend to be with the server itself, not with the request. _ Before I contact the person who manages the server and hosting (essentially asking if the error is on his end) is there a chance I could have created an issue with an incorrect 301 redirect or other code added to .htaccess incorrectly? Here is the 301 redirect code I am using in .htaccess: RewriteEngine On RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/.]+/)*(index.html|default.asp)\ HTTP/ RewriteRule ^(([^/.]+/)*)(index|default) http://www.example.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} !^(www.example.com)?$ [NC] RewriteRule (.*) http://www.example.com/$1 [R=301,L] Could adding the following code after that in the .htaccess potentially cause any issues? BEGIN EXPIRES <ifmodule mod_expires.c="">ExpiresActive On Intermediate & Advanced SEO | | kimmiedawn
 ExpiresDefault "access plus 10 days"
 ExpiresByType text/css "access plus 1 week"
 ExpiresByType text/plain "access plus 1 month"
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType application/x-javascript "access plus 1 month"
 ExpiresByType application/javascript "access plus 1 week"
 ExpiresByType application/x-icon "access plus 1 year"</ifmodule> END EXPIRES (Edit) I'd like to add that there is a Wordpress blog on the site too at www.example.com/blog with the following code in it's .htaccess: BEGIN WordPress <ifmodule mod_rewrite.c="">RewriteEngine On
 RewriteBase /blog/
 RewriteRule ^index.php$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /blog/index.php [L]</ifmodule> END WordPress Thanks0
 
			
		 
			
		 
			
		 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				