Solved

PHP and 301 redirect

Posted on 2011-02-18
5
228 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

867 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

16 Experts available now in Live!

Get 1:1 Help Now