Url Friendly - redirect 301 or 200

Hi E's,
In this question I get a solution for have friendly URL's in my project: http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28484783.html.
What this solution does is check the URL, and if the URL does not exist redirects to router.php. Router.php analyze the URL, and if the friendly URL exists, redirect to the current page. Example: Friendly URL = domain.com/friendly-url correspond to domain.com/friendly_url-php?bla=bli, if I write domain.com/friendly-url router.php send to the page  domain.com/friendly_url-php?bla=bli.
This photo shows how the system works:The script workingThe system work perfect, the problem is Google assumes a 302 Redirect, when the correct is 301 (the page has been moved permanently) or maybe 200 (the server successfully returned the page).

I thing the problem is the code of .htaccess, don't inform the type of redirect:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ router.php [L]

Open in new window

I try change the last line to:
RewriteRule ^.*$ router.php  [R=301,L]

Open in new window

But not work

Router.php have this code
//I will check url and redirect page based and that url
header( "Location: article.php?id=878" ) ; 

Open in new window

What changes I have to do for the redirect be 301 or 200?

The best regards, JC
Pedro ChagasWebmasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jessica WhitleySoftware DeveloperCommented:

This site explains how you can create redirects without url changes in Php by 3 dideferential methods and also explains why bing and Google downgrade redirects to sites with the same names. Google and Bing view sites with the same names as security issues and automatically  don't allow access. They are really just trying to protect us. However, for development this can become annoying. Using direct linK redirects is what I would recommend in this situation. Just be sure you have the entire url in the link or it will not working correctly.
in router.php, add a header call:
header("HTTP/1.1 301 Moved Permanently");
header( "Location: article.php?id=878" ) ;

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Pedro ChagasWebmasterAuthor Commented:
Hi @hielo, thank your for your answer.
In your opinion, in this case, what is the best redirect, 301 or 200?

The best regards, JC
I would use a 301.  You are redirecting after all.  The 200 is what the client receives when the requested resource is found and served immediately (without resorting to redirection).
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Check out slim framework for routing.  Or at least how they suggest http://docs.slimframework.com/routing/rewrite/

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.