Solved

How to put SEO Friendly Redirection on same script?

Posted on 2009-07-09
4
235 Views
Last Modified: 2013-12-13
I am having a single script "index.php" which reacts differently as per querystrings. Lets say: If some one browse my site with this url:

http://www.mysite.com/  or http://www.mysite.com/index.php  It opens the home page of website.

and

When someone put url like this: http://www.mysite.com/?category=sports It open different section of the same page. (It usually show a list of items , which matched with this category instead of actual home page)

So the same script index.php reacts differnetly depend upon the query string passed to it.

Now the problem is, I want to separate this fe=uncinality of this script to a new script because the index.php is become too heavy to load and take lot of time to even show the home page.

I have already lot of traffic on my site and I dont want to loose any single incoming link to my site. My site is already crawled by google.

I want to put such re-direction on the script so that it will be a SEO friendly. I know if it will be the case of shifting script, I can put 301 redirect and do the job. But the problem is I also want the index.php will react as it is and will show home page always. So I made two scripts. One is index.php itself and other one I created to show the list of categories like this: http://www.mysite.com/browse/?category=sports.

So I want to redirect the part of the index script; this url: http://www.mysite.com/?category=sports  to http://www.mysite.com/browse/?category=sports

How can I do it, so that it will be SEO friendly and wont effect index.php anyway.

Thanks
0
Comment
Question by:proteam4
  • 2
  • 2
4 Comments
 

Author Comment

by:proteam4
ID: 24814901
In index.php to redirect old urls to new urls, I am doing like this in code below. Please let me know if it is the correct way of doing this?


    $urlQueryString = $_SERVER['QUERY_STRING'];
    
    if ($urlQueryString){
        header( "HTTP/1.1 301 Moved Permanently" );
        header( "Location: http://" . $_SERVER['HTTP_HOST'] . '/browse/' . $urlQueryString ); 
    }  

Open in new window

0
 
LVL 7

Accepted Solution

by:
namol earned 500 total points
ID: 24814935
You could do so by using mod_rewrite with an .htaccess file.

Put this in a .htaccess file in the root of your website.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{QUERY_STRING} category=(.*)
RewriteRule ^index(.*) /browse/?category=%1
0
 

Author Comment

by:proteam4
ID: 24814967
Thanks for the solution. I can do this but I want to know the following queris though : before implementing the solution:

1) Which one will be the faster? Code or htaccess ?

2) Will it be SEO Friendly? So the existing index.ph wont get affected with this redirection and works normally on google or any other search engine?

Thanks
0
 
LVL 7

Expert Comment

by:namol
ID: 24815264
It is SEO friendly, you can even add a [r=301] to the last line of the rewrite rule to permanently update the search engine links. As to what is faster, i'd say the htaccess is because it gets interpreted before the code is actually processed. If pages are loading rather slowly etc, you might want to enable gzip compression on the server side to speed up deliver of the content.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Link failure 16 60
PHP encrypted string and passing to a ASP Page 12 36
MySQL Persistent Connections 10 30
Converting PHP triple des decrypt to c# 9 62
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

680 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