Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 244
  • Last Modified:

PHP and 301 redirect

I thought 301 redirecting some dynamic pages would be as simple as putting the following code at the top of my dynamic page:

Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.firstclasscomponents.com" );
exit(0);

Open in new window



However it seems this is not the case since it produces a 302 instead.

Basically the dynamic page has a url that looks like this http://www.mysite.com/AD9505Z2.html

and the AD9505Z2 is part of a what gets queried in the database so that the records information is used in the page.

I use a .htaccess file to do the rewrite. So that looks like this:

RewriteRule (.*)\.html /part_info.php?url=$1

Open in new window


Well the page works fine, but I actually wanted to wipe out all the pages from google and do a 301 to the home page of the site. However everything I have tried has just produced 302's. Does anyone have any thoughts. I have tried all kinds of different things and nothing is working.

0
tarrigo
Asked:
tarrigo
  • 2
  • 2
1 Solution
 
andreizzCommented:
<?header( "HTTP/1.1 301 Moved Permanently" );header( "Status: 301 Moved Permanently" );header( "Location: http://adress/" );exit(0); ?>

Open in new window


this works
0
 
VanHackmanCommented:
The code that you have provided is correct.

Also you could try to do a httacess redirection:


Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Please REPLACE www.newdomain.com in the above code with your actual domain name.

Open in new window

0
 
tarrigoAuthor Commented:
Unfortunately those solutions did not work. Still get the same problem. It keeps coming back with the following results:

Checked link: http://www.mysite.com/AD9505Z2.html

Type of redirect: 302 Found

Redirected to: http://www.mysite.com/ZiUfZ/AD9505Z2.html 

0
 
VanHackmanCommented:
In this case is more probably that your server is ignoring the configurations.
Because the solutions provided above are quite enough for what you are needing.
Ask your hosting provider about if it does have some restriction regarding this kind of redirection.

because whithout looking at the real site I'm unable to help you better... =P


Kind regards,
VanHackman
0
 
tarrigoAuthor Commented:
Didn't solve the problem, but it might have guided down the right road.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now