• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • Last Modified:

Indexed file in google?

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
MOSTAGHASSI
Asked:
MOSTAGHASSI
  • 7
  • 7
  • 6
2 Solutions
 
Michel PlungjanIT ExpertCommented:
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
 
MOSTAGHASSIAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
from the article I would think

rewriteEngine on
rewriteRule /music/artistpage\.php /music/artispage.php [R=permanent,L]
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
fiboCommented:
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
 
MOSTAGHASSIAuthor Commented:
@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
 
Michel PlungjanIT ExpertCommented:
$extra = 'artispage.php';
$artistID = htmlentities($_GET("artistid"));
header("Location: http://$host$uri/$extra?artistid=".$artistID);
0
 
fiboCommented:
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
 
Michel PlungjanIT ExpertCommented:
I would still be careful of what was passed to the page
0
 
MOSTAGHASSIAuthor Commented:
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
 
MOSTAGHASSIAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:
Add? You can redirect to any page but only one page per file name. In htaccess you can have a list of pages
0
 
MOSTAGHASSIAuthor Commented:
oh,please forget it ,it is clear that for each page i must make a page with this pice of code.
0
 
Michel PlungjanIT ExpertCommented:
Right
0
 
MOSTAGHASSIAuthor Commented:
thanks for all comments and solutions.
0
 
fiboCommented:
@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
 
fiboCommented:
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
 
Michel PlungjanIT ExpertCommented:
I have 25 redirects in my htaccess. Never had an issue. I can probably remove them by now
0
 
fiboCommented:
@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
 
MOSTAGHASSIAuthor Commented:
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
 
fiboCommented:

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 7
  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now