Link to home
Start Free TrialLog in
Avatar of Pedro Chagas
Pedro ChagasFlag for Portugal

asked on

Url Friendly - redirect 301 or 200

Hi E's,
In this question I get a solution for have friendly URL's in my project: https://www.experts-exchange.com/questions/28484783/Mod-rewrite-Information-from-data-base.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:User generated imageThe 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
<?php
//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
SOLUTION
Avatar of Member_2_6317024
Member_2_6317024
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Pedro Chagas

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial