?
Solved

Indexed file in google?

Posted on 2011-02-28
20
Medium Priority
?
433 Views
Last Modified: 2013-12-09
Hello all experts;

On my website i had a page with  artistpage.php ;but on my new site version i changed that page to artispage.php ,so when the users search in google they reach to first page(artistpage.php) for this i have a 404.html file that guide users to new page.

Now my question is:
If i waite does google correct the old indexed file(artistpage.php) with new one?

thanks in advance
0
Comment
Question by:MOSTAGHASSI
[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
  • 7
  • 7
  • 6
20 Comments
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 400 total points
ID: 35004053
Just change your htaccess to redirect with a permanently moved stautus - the user will see the new page regardless and goggle will remove the old page from cache.
http://www.somacon.com/p145.php
0
 

Author Comment

by:MOSTAGHASSI
ID: 35004669
I have this dir:

www.mydomain.com/music/artistpage.php 

please let me know that how must i write the code in htaccess for new condition

www.mydomain.com/music/artispage.php 
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35005018
from the article I would think

rewriteEngine on
rewriteRule /music/artistpage\.php /music/artispage.php [R=permanent,L]
0
Flexible connectivity for any environment

The KE6900 series can extend and deploy computers with high definition displays across multiple stations in a variety of applications that suit any environment. Expand computer use to stations across multiple rooms with dynamic access.

 
LVL 29

Accepted Solution

by:
fibo earned 1600 total points
ID: 35006479
1 - Since you are working with php, I would really avoid to make an htaccess change just for one page: I would make the redirect using php itself (would work also if you cannot access htaccess)
see http://www.php.net/manual/en/function.header.php

In your case, you would create a file /music/artistpage.php which would contain
<?php
header("HTTP/1.0 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'artispage.php';
header("Location: http://$host$uri/$extra");
exit;
?>

2 - If you do it with htaccess, I would use R=301 to be sure that the robots take note (I am not sur that R=permanent will do the same in all conditions)

3 - If your redirects, whether htaccess or php or other, are sending the 301 code, then the following will happen:
a - your visitors will be silently redirected to the correct page, without being aware of the change
b - your robots visitors will be redirected but will also be informed that the page has been moved permanently and that they should update their info.

a/ will solve any short-term problem of visitors, whether they come directly (eg some bookmark) or thru a search engine
b/ will solve the "long term problem" of the correct content being correctly indexed as being part of the correct page at the correct address

Once the new page will have been indexed by Google, if the "old" page is still indexed, you can consider 2 options:
I - Tell Google and other engines to de-index the old page
II - Keep things as they are. This will slightly penalize the new page... but I would select this option.

Your html page solution is usually NOT a good solution, since it just disturbs the visit process. You might alternatively improve it by placing a javascript redirect (which would be ignored by non-javascript users, including spiders) or directly an html redirect with metatags: see
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_redirect

but I would really prefer the 301 redirect thru php...
0
 

Author Comment

by:MOSTAGHASSI
ID: 35008435
@fibo
Thanks,i did your suggestion because i don't have access to htaccess but some problems:

If people come from search engines, they went(before) to a specific id like

www.mydomain.com/music/artistpage.php?artistid=25

but now go to

www.mydomain.com/music/artispage.php(information regarding artistid=25 is missed)

so this is better than 404.html  but is there any solution that they redirect to e.g(this depend on they search)
www.mydomain.com/music/artispage.php?artistid=25     

-As my understanding, after this correction i must waite that search engines correct thier indexed files regarding my page ,and if they do it, i perefer to do this.


0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35008497
$extra = 'artispage.php';
$artistID = htmlentities($_GET("artistid"));
header("Location: http://$host$uri/$extra?artistid=".$artistID);
0
 
LVL 29

Expert Comment

by:fibo
ID: 35009975
A more general solution would be

<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'artispage.php';
$query_string=trim('?' . $_SERVER['QUERY_STRING']);
if ('?' == $query_string) $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>

Open in new window


Page http://www.php.net/manual/fr/reserved.variables.server.php gives a complete list of the server variables you can use for the redirect.

For the indexing problem: 301 redirect is really the right weapon! It will take 1 day - 6 weeks for the "new" page to get indexed (in your case I'm pretty sure it is already), and most robots will find it to.

There are other search / indexing actions you might consider, but they go quite farther than your initial "single page" question.

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35010061
I would still be careful of what was passed to the page
0
 

Author Comment

by:MOSTAGHASSI
ID: 35010486
Thanks ,it is ok,just an another small question,if i want that add another page ,like:

<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'anotherpage.php';
$query_string=trim('?' . $_SERVER['QUERY_STRING']);
if ('?' == $query_string) $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>
0
 

Author Comment

by:MOSTAGHASSI
ID: 35010508
my mean is that i repeat the code for each page like:

<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'artispage.php';
$query_string=trim('?' . $_SERVER['QUERY_STRING']);
if ('?' == $query_string) $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>

<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'anotherpage.php';
$query_string=trim('?' . $_SERVER['QUERY_STRING']);
if ('?' == $query_string) $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35010523
Add? You can redirect to any page but only one page per file name. In htaccess you can have a list of pages
0
 

Author Comment

by:MOSTAGHASSI
ID: 35010524
oh,please forget it ,it is clear that for each page i must make a page with this pice of code.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35010533
Right
0
 

Author Closing Comment

by:MOSTAGHASSI
ID: 35010564
thanks for all comments and solutions.
0
 
LVL 29

Expert Comment

by:fibo
ID: 35010787
@MOSTAGHASSI:
mplungjan is right in warning that passing "query_string" might be dangerous and the php redirect might be an occasion to secure this.

In your case if the artist id would be the only parameter legally passed, using the sanitizing code suggested by mplungjan into my own code would give something like
<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'artispage.php';
$artistID = trim(' ' . $GET['artistid']);
if ('' < $artistID) {$query_string = '?artistid=' . htmlentities($artistID);} else $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>

Open in new window

The use of htmlentities protects against any attempt to attack by SQL injection (eg, using the ' charcter) or crosss scripting (eg a malicious user giving as an artist name   <script>alert('under attack')</script> or something really more dangerous)
0
 
LVL 29

Expert Comment

by:fibo
ID: 35010996
B-) glad we could help. Thx for the grade and points.

Answers ande comments were published while I was working on my previous answer...

For your "several pages" problem, you might consider 2 different paths
1 - Create a rediect page for each old page and the new page it redirects to
2 - IF in your specific case you have lots of such pages AND they all use the artistid page... you could use include files to make things easier (see below)

BUT if you have lots of pages to redirect AND you are using some recent CMS like Drupal or Joomla, they have tools to redirect automatically
-----
Using included files:
artistpage.php:
<?php
$extra = 'artispage.php';
require_once('redirect.inc');

Open in new window

oldpage2.php
<?php
$extra = 'anotherpage.php';
require_once('redirect.inc');

Open in new window

NOTE: these files are 3 lines long, no space before <?php
Included file    redirect.inc
<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$query_string=trim('?' . $_SERVER['QUERY_STRING']);
if ('?' == $query_string) $query_string = '' else $query_string = htmlentities($query_string);
header("Location: http://$host$uri/$extra$query_string");
exit;

Open in new window

NOTE: this file has no space before <?php and does not have the closing ?> which you should never put in included files

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35011127
I have 25 redirects in my htaccess. Never had an issue. I can probably remove them by now
0
 
LVL 29

Expert Comment

by:fibo
ID: 35011647
@mplungjan,
25 redirects is certainly not a problem, except when comes maintenance time
removing those now useless can do no harm!

I usually have 3 sets of rewrites
- redirecting non-www to www (or the reverse depending on the objective)
- specific rewrites, usually to solve legacy problems as is the case here
- automated rewrites by the package being used (eg, cms, blog, e-commerce, etc)

B-) keeping the 2nd part as small as possible is the ultimate goal!
0
 

Author Comment

by:MOSTAGHASSI
ID: 35012063
Thanks,regarding the security issue, in my new page i have this code

$urlcome = utf8_decode(htmlspecialchars($_GET["artistid"])); //these 2`lines are for injection protection.
$urlcome = mysql_real_escape_string($urlcome);

so do you think that is this ok or  i must use your new codes:

<?php
header($_SERVER['SERVER_PROTOCOL'] . " 301 Permanently redirect");
$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'artispage.php';
$artistID = trim(' ' . $GET['artistid']);
if ('' < $artistID) {$query_string = '?artistid=' . htmlentities($artistID);} else $query_string = '';
header("Location: http://$host$uri/$extra$query_string");
exit;
?>

0
 
LVL 29

Expert Comment

by:fibo
ID: 35015200

1

Beware mysql_real_escape_string: it requires some mysql connection to be active, otherwise it will fail. This is not a "general weapon", it is limited to database interaction situations (yes, if you want to prevent sql injection, you are in such an environment... but in your example here it would fail since mysql is neither active nor otherwise needed)

2

htmlspecialchars has an effect more limited than htmlentities.... so I would prefer this last one just to be safe. Note that both will make no change to usual strings of letters and digits, will create a slight change on the apostrophe (non-malicious in most situations, but essential to malicious uses) and big changes to strings with characters like < and >... which are not that common in most names.

3

utf8 pinpoints another story, which should be decoupled from security issues. If you happen to have found you need it, go ahead. Otherwise, be careful not to open some Pandora box.

To be more precise:
if your site is in English, you can probably ignore utf8 in most situations
otherwise, you probably need (now or later) to have your site fully in utf8, but this is really a nightmare and should be carefully planned. (FYI: your php files will need to be in UTF8 WITHOUT BOM otherwise your redirects will fail; your html generated files will need to select utf8; your sql data might need to be reconfigured...)

4. Conclusion

I would probably stick to "my" code (well, with the protection part coming from mplungjan's code) which uses a minimum set of functions to handle the injections process.
0

Featured Post

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

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

WARNING:   If you follow the instructions here, you will wipe out your VTP and VLAN configurations.  Make sure you have backed up your switch!!! I recently had some issues with a few low-end Cisco routers (RV325) and I opened a case with Cisco TA…
Make the most of your online learning experience.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

800 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