Solved

PHP and 301 redirect

Posted on 2011-02-18
5
227 Views
Last Modified: 2013-11-19
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
Comment
Question by:tarrigo
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:andreizz
ID: 34926089
<?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
 
LVL 11

Expert Comment

by:VanHackman
ID: 34926141
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
 

Author Comment

by:tarrigo
ID: 34926689
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
 
LVL 11

Accepted Solution

by:
VanHackman earned 500 total points
ID: 34929330
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
 

Author Closing Comment

by:tarrigo
ID: 36372093
Didn't solve the problem, but it might have guided down the right road.
0

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This video teaches users how to migrate an existing Wordpress website to a new domain.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now