SEO: Is a redirect without using 301 but a PHP script, OK?

SEO: Is a redirect without using 301 but a PHP script, OK? - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the SEO: Is a redirect without using 301 but a PHP script, OK? error on your web browser. Problem :


I've been reading about redirection, and how it can affect (or not if done properly) SEO.


I'm changing my website's content platform from Drupal to a PHP custom made code.


In my current site I have two links that point to the same link like this:



.../node/123


.../my-node-title



Mainly because Drupal allows you to create a custom-made links, so every article has a default one (node/123) and the custom-made one (/my-node-title).


My question is about what to do in order to prevent losing any SEO that each link may have.


In the new website all articles are structured like this: content.php?id=123


I've stored in the database the custom-made link of every article.


Instead of doing a 301 redirect I'm rewriting all links that do not exist to be redirected to redirect.php page to process the request. There I take the string from the link, look for it in the database and redirect the user.


The process is like this:


in .htaccess file:


RewriteRule ^.*$ ./redirect.php

In redirect.php:


I grab the $_SERVER['REQUEST_URI'] and using explode() I get the last part of the link (ie. my-node-title), look for it in the database and grab the ID of the article (ie. 123) and save it in a $link variable.


Then I use header() function and do the redirect: header('Location: '.$link);


So, people still click on .../my-node-title but when the article loads at the navigation bar appears /content.php?id=123


I would like to know your comments about this solution. I know that with SEO there are not fixed rules, or certainty in anything, but I would like to know if what am I doing is acceptable. Thanks!


Solution :

Use 301 redirect before location:



header("HTTP/1.1 301 Moved Permanently");


Also, You can use rewrite rule with 301 for each article in htaccess. Htaccess generated each time by php script in cron and/or when new article is added. This serves request faster then redirect.php if you have less then thousands of articles. This was you can make human readable urls for articles also.

This way you skip execution of php and one db request to grab article name and find id.



Here is how one of my htaccess looks like: Part between special comments replaced by script, all other configuration keeps unchanged by script:



# here non rewrite options, skipped
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %HTTP_HOST ^www.(.*) [NC]
RewriteRule ^(.*)$ https://%1%REQUEST_URI [R=301,L]
# startreplace
RewriteRule ^HumanReadableTitle1.html$ blog.php [E=HumanURL:1,L]
RewriteRule ^HumanReadableTitle2.html$ certificates.php [E=HumanURL:1,L]
RewriteRule ^HumanReadableTitle3.html$ blog_post.php?id=15 [E=HumanURL:1,L]
RewriteRule ^HumanReadableTitle4.html$ blog_post.php?id=16 [E=HumanURL:1,L]
# endreplace
</IfModule>


'HumanReadableTitles' readed from DB. UTF8 encoded, but not URL encoded, mod_rewrite allow this.


We hope that this article has helped you resolve the seo, redirects, php error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=