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 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
-
Redirection Problem
I have a site that has 2,50,000 pages and I want to redirect to another domain. Is it good practice for SEO and google?
Intermediate & Advanced SEO | | MuhammadQasimAttari0 -
For URLs that require login, should our redirect be 301 or 302?
We have a login required section of our website that is being crawled and reporting as potential issues in Webmaster Tools. I'm not sure what the best solution to this is - is it to make URLs requiring a login noindex/nocrawl? Right now, we have them 302 redirecting to the login page, since it's a temporary redirect, it seems like it isn't the right solution. Is a 301 better?
Intermediate & Advanced SEO | | alecfwilson0 -
Url rewrite & 301 redirects
Hi all I am having some issues rearding url rewrites and 301 redirects with 1 and 1 hosting and am unsure of the best approach. The website is a custom made shopping cart system with categories and products. The current urls for categories are : index.php?l=product_list&c=1 The new url format required is : /banner-stands The current urls for products are : index.php?l=product_detail&c=1&p=1 The new url format required is : /banner-stands/banner-stand Thanks
Intermediate & Advanced SEO | | vividwebdesign0 -
301 redirect subdomain to path and 301 for popular pages
We have very popular pages that have many backlinks. www.chezmaya.com/jeux/game33.htm have so many backlinks and it's very popular. Now If i'm moving this page to a new path like : http://www.chezmaya.com/jeux/component/mtree/Défouloir/Game33/details.html with a 301. Your SEOmoz toolbar is now giving a very low PA:1 and mR:0.00 for this new page. My question is after you crawl my site again would you change the values to what /jeux/game33.htm got before ? We used to have jeux.chezmaya.com and moved to www.chezmaya.com/jeux/
Intermediate & Advanced SEO | | SocialGeekMedia
Same here PA:1 and mR:0.00 for this page. Also Matt Cutts say that Google does transfer the juice from the old page to the new one. I already saw one url changed in a search for puzzle, it's at the same position it was before, but it say's 6 days ago beside. So I wonder if this is temporary and it will move with time? Thanks0 -
Redirection not working
http://elmanarah.com/ to http://www.elmanarah.com/ I have mistakenly created 5 databases for one wordpress installation.In order to get rid of them I mistakenly even deleted the right one.Now created the new one but the URL is showing with www Even now if It type in http://elmanarah.com/ it sends me to http://www.elmanarah.com/ I also check in URL D.A and P.A in OSE it shows like I have redirected it fine.Can anyone Check in and guide me either I have done it right and It pass on my previous work effort or it was total loss for me?
Intermediate & Advanced SEO | | csfarnsworth0 -
Is it a problem to have too many 301 redirects within your site
my website is translated into 10+ languages, but our news articles are often only published in 1-2 languages. Currently, URLs are created in the unpublished news languages that then 301 redirect the user to main news page since the content doesnt exist in that language. Is this implementation okay or is there a preferred method we should be using so that we don't have a large number of pages on the site with redirects? Thanks!
Intermediate & Advanced SEO | | theLotter0 -
Should you ever reverse a 301
Hi Im Looking at reversing a 301 i did 5 months ago, I originally changed names of a site for reasons where the site was going to be split into 2 where part of the site i would run and the other where i would get my business partner to run it However since the 301 i have lost 80% of traffic and cannot find the reason as to what especially as everything looks perfect except the rankings, to put it into context 150 keywords i was tracking all were page 5 and below with 40% being page 1 Now only 7 from that same 150 are in the top 10 pages (First 100 results), The issue i have must be very rare as i have posted for help with little or no response, which tells me that the kind people who have looked could not see any issues as this is normally a very helpful community (below is the last thread i asked for help) http://www.seomoz.org/q/301-redirect-how-to-get-those-juices-flowing So 5 months on i am considering removing the 301 and hoping that some kind of normality returns by reinstating the old URL So my question is that is what im about to do wise, do i have any options, is this something you have done in the past if so how did you get on Thanks in advance
Intermediate & Advanced SEO | | kellymandingo0 -
Open Site Explorer not Seeing 301 Redirect to non-www
I cannot figure out why open site explorer doesn't see that when you go to http://preferredroofingkc.net/ it redirects to http://www.preferredroofingkc.net/ This is a wordpress installation that uses a cannonical url http://www.preferredroofingkc.net/ The HTACCESS file also has a 301 redirect as follows: RewriteEngine On
Intermediate & Advanced SEO | | RobertFisher
RewriteBase /
RewriteCond %{HTTP_HOST} ^preferredroofingkc.net [NC]
RewriteRule ^(.*)$ http://www.preferredroofingkc.net/$1 [L,R=301] But, open site explorer still shows these sites separately without alerting that there is a 301 redirect.0