?
Solved

PHP and 301 redirect

Posted on 2011-02-18
5
Medium Priority
?
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

777 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