Search engine-oriented URL optimization

Source: Internet
Author: User
Tags function definition header

I wrote the Jin Far Information Network (www.geofuture.net) did not take into account how the URL to the search engine optimization, completed before the start of optimization. At this point to consider the static on the one hand URL, on the one hand to keep the original program as far as possible to facilitate maintenance later, so the use of Url_rewrite method. The following is the corresponding section of the httpd.conf

<virtualhost *:80>
Documentroot/home/geofuture
ServerName www.geofuture.net
Serveralias *.geofuture.net geofuture.net *.cic123.com
DirectoryIndex index.files index.html index.php
Rewriteengine on
#RewriteLog Logs/rewrite.log
#RewriteLogLevel 9
#RewriteRule/http://geofuture.vicp.net/[L]
Rewritecond%{request_filename} index.files [OR]
Rewritecond%{request_filename} error.files [OR]
Rewritecond%{request_filename} cat.files [OR]
Rewritecond%{request_filename} area.files [OR]
Rewritecond%{request_filename} info.files [OR]
Rewritecond%{request_filename} topic.files [OR]
Rewritecond%{request_filename} post.files [OR]
Rewritecond%{request_filename} profile.files [OR]
Rewritecond%{request_filename} userinfo.files [OR]
Rewritecond%{request_filename} cert.files [OR]
Rewritecond%{request_filename} revise.files [OR]
Rewritecond%{request_filename} review.files [OR]
Rewritecond%{request_filename} feedback.files [OR]
Rewritecond%{request_filename} keyrank.files [OR]
Rewritecond%{request_filename} rss.files
Rewriterule ^ (. +?) \q (. *) $ $1=$2 [N]
Rewriterule ^ (. +?) ZZ (. +) $ $1&$2 [N]
Rewriterule ^ (. +?) \.files (. *) $ $1.php$2 [N]
Rewriterule ^ (. +?) \.php (/|&) (. +). html$ $1.php?$3 [L]
ErrorDocument 400/error.php?status=400
ErrorDocument 401/error.php?status=401
ErrorDocument 403/error.php?status=403
ErrorDocument 404/error.php?status=404
ErrorDocument 405/error.php?status=405
ErrorDocument 408/error.php?status=408
ErrorDocument 410/error.php?status=410
ErrorDocument 411/error.php?status=411
ErrorDocument 412/error.php?status=412
ErrorDocument 413/error.php?status=413
ErrorDocument 414/error.php?status=414
ErrorDocument 415/error.php?status=415
ErrorDocument 500/error.php?status=500
ErrorDocument 501/error.php?status=501
ErrorDocument 502/error.php?status=502
ErrorDocument 503/error.php?status=503
ErrorDocument 506/error.php?status=506
</VirtualHost>

I only to the content-oriented column optimization, as for the login and search and other parts remain unchanged, because these parts are also search engines do not care. At the same time, some common status codes (HTTP status) also have corresponding static pages. Only the URL of the foreign request was modified, and the URL generated by the program is implemented in the following code:

<?php
--------------Section NAME-----------------------------------
Dynamic URLs are rewritten as static
function Url_rewrite ($buffer)
{
return $buffer;
$search = Array (
'. php ',
'?',
' & ',
' Fileszz ',
'=',
' Hrefq ',
);
$replace = Array (
'. Files ',
'/',
' ZZ ',
' Files/zz ',
' Q ',
' Href= ',
);
Preg_match_all ('/href= "\/(index|error|cat|area|info|topic| post|profile|userinfo|cert| revise|review|feeback| KEYRANK|RSS) \.php (. *?) " /', $buffer, $match);
$url = Str_replace ($search, $replace, $match [0]);
$url = Preg_replace ('/\.files (. +?) (#.+?)?" $/', '. files\\1.html\\2 ', $url);
return Str_replace ($match [0], $url, $buffer);
}
?>

The function definition above is placed in the public header file. Then, add the following code at the beginning of the page where you want to optimize:

Ob_start ("Url_rewrite");

This is the only place where the original program needs to be modified. There is another problem with this. For example, I write pagination functions such as code, all require the original dynamic URL, and optimized later through the $_server[' php_self '. $_server[' query_string '] can only be optimized after static URLs, all dependent on the dynamic URL code must be modified to be able to handle the original URL and optimization. This has to overwrite many of the common header file's code. So I thought of a roundabout way:

<?php
--------------Section NAME-----------------------------------
Revert to dynamic URL
function Url_resume ($url)
{
$search = Array (
'. Files ',
'. php/',
' ZZ ',
'/zz ',
' Q ',
'. html ',
);
$replace = Array (
'. php ',
'. php? ',
' & ',
'?& ',
'=',
'',
);
$url = Str_replace ($search, $replace, $url);
return $url;
}
?>

With the above function, you can call a dynamic URL wherever you want it, without rewriting the core functions. It should be noted that Url_rewrite and Url_resume are the opposite processes, but their parameters are different. The former argument is the entire buffer, which is just a single URL, because the recovery is rare, and global processing overrides can improve speed.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.