Pseudo-static in the SEO fiery era, is that every webmaster are more concerned about the issue, discuz! Forum how pseudo-static, why pseudo-static failure, why the list page can not achieve pseudo-static, why some pages are not pseudo-static it? The following DZ official nxy105 from two angles for everyone analysis under discuz! X2 is how to implement pseudo-static functions.
First, discuz! pseudo-static is how to function
We all know that when we access a page through an address, we access an entity file on the server. For example, access
- Http://www.xxx.com/index.html
Copy Code
, you are accessing the index.html file under the root of the Web site. However, for the forum, if each page (subject list, content page) is a static entity file, the number of files will be much, and can not be dynamic real-time presentation of the content of the forum. If only dynamic access is used, it is not conducive to enhancing the friendly side of the search engine, so we will use pseudo-static, showing the form of a static page such as HTML, which is actually still handled by dynamic scripting.
discuz! The pseudo-static processing of the X2 utilizes the server's rewrite module to convert the requested URL through the rules of the configuration of the rewrite module.
Below we take the Apache rewrite module as an example, detailed explanation.
- Rewriterule ^ (. *)/forum-(\w+)-([0-9]+) \.html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1
Copy Code
This is an Apache pseudo-static rule.
The rewrite rule matches the URL request of/forum-xx-xx.html, after the rule conversion, the actual requested link is/forum.php?mod=forumdisplay&fid=xx&page=xx, is not very familiar with , this is the dynamic link that asks for a list of forum topics.
So the question is, if the pseudo-static request fails/forum-xx-xx.html, the hint page can not be displayed, there are several possible errors?
1, pseudo-static rules to take effect is there?
If the server does not support rewrite, if you forget to restart the service, if the. htaccess file is placed in the wrong location, and so on, it is possible that the rewrite function is not running, so it certainly does not work oh. Therefore, first check the rewrite function is normal, if the use of space, you can consult the space quotient said.
2. Is the rule wrong?
If this is the rule,
- Rewriterule ^ (. *)/forum-(\w+)-([0-9]+) \.html$ $1/forum.php?mod=forumdisplay
Copy Code
Something is missing, so/forum-xx-xx.html only accesses/forum.php?mod=forumdisplay, so the list page definitely doesn't show
If the rules are more exaggerated
- Rewriterule ^ (. *)/forum-(\w+)-([0-9]+) \.html$ $1/forumdisplay.php&fid=$2&page=$3&%1
Copy Code
forumdisplay.php This file is not available, the page certainly cannot be displayed, which explains why some of the rules of previous versions (such as X1.5 and 7.0) could not be used directly in X2.
So the correct rule is the page can be normal access to the premise, if the use of new rules, found inaccessible, first check the rules are not written wrong. (In fact, these in the background of the forum pseudo-static settings can be checked to, do not have the webmaster bother you)
3. Do you have a normal network?
If desperately in pseudo-static search for reasons, did not pay attention to the site has not been able to access, is a kind of impossible feeling, the site can not access the reason please refer to the official forum related tutorials.
Analysis to this step, I believe we have a certain understanding of how pseudo-static work, then we turn to the next question.
Second, how pseudo-static is displayed in the forum?
Why my station pseudo-static open, but on the first page or show dynamic link ah? So the following explains how pseudo-static is displayed.
Understand discuz! 's classmates should know that in the Forum template file, so the URL links are in the form of dynamic return output. (Static links are not visible in the template?) YES) as a general rule, dynamic links should be displayed, and how static links are implemented.
In the footer.htm file of the template file, there is a line of code.
- <!--{eval output ();} -
Copy Code
After parsing this code, the output () function in function_core.php is called directly.
Let's take a look at what the output function has done.
- if ($_g[' setting ' [' Rewritestatus '] | |!empty ($havedomain))
- {
- $content = Ob_get_contents ();
- $content = Output_replace ($content);
- Ob_end_clean ();
- $_g[' gzipcompress '? Ob_start (' Ob_gzhandler '): Ob_start ();
- Echo $content;
- }
Copy Code
When the program executes here, it executes a $content = Ob_get_contents (), ob_get_contents () gets all the data in the current output cache, that is, the page returned by the template is not displayed directly to the user, but is The content variable gets to the. Then enter the Output_replace function to perform the content substitution (various substitutions, not just the pseudo-static chain replacement), and finally the echo output.
The replacement work is then placed in the Output_replace function,
- if (!empty ($_g[' setting ' [' Output '] [' str '] [' Search '])
- {
- if (Empty ($_g[' setting ' [' Domain '] [' app '] [' Default '])) {
- $_g[' setting ' [' Output '] [' str '] [' replace '] = Str_replace (' {curhost} ', $_g[' SiteURL '), $_g[' setting ' [' Output '] [' Str ' [' replace ']);
- }
- $content = Str_replace ($_g[' setting ' [' Output '] [' str '] [' search '], $_g[' setting ' [' Output '] [' str '] [' replace '], $ content);
- }
Copy Code
This section, replacing the domain name of the current site, replaces the ' {curhost} ' placeholder written in the template with the value of $_g[' SiteURL '.
- if (!empty ($_g[' setting ') [' Output '] [' preg '] [' Search '])
- {
- if (Empty ($_g[' setting ' [' Domain '] [' app '] [' Default '])) {
- $_g[' setting ' [' Output '] [' preg '] [' search '] = Str_replace (' \{curhost\} ', Preg_quote ($_g[' SiteURL '), $_g[' setting ') [' Output '] [' Preg '] [' Search ']);
- $_g[' setting ' [' Output '] [' preg '] [' replace '] = Str_replace (' {curhost} ', $_g[' SiteURL '), $_g[' setting ' [' Output '] [' Preg ' [' replace ']);
- }
- $content = preg_replace ($_g[' setting ' [' Output '] [' preg '] [' search '], $_g[' setting ' [' Output '] [' preg '] [' replace '], $ content);
- }
Copy Code
This part is to replace the pseudo-static link, the specific implementation process, I briefly introduced, not interested classmates can skip.
$_g[' setting ' [' Output '] [' preg '] [' search '] the data stored in the array, similar to
/<a href\= "() forum.php\?mod\=forumdisplay& (amp;)? fid\= (\w+) (&page\= (\d+))?" ([^\>]*) \>/e
One of the data in the corresponding $_g[' setting ' [' Output '] [' preg '] [' replace ']
Rewriteoutput (' Forum_forumdisplay ', 0, ' \1 ', ' \3 ', ' \5 ', ' \6 ')
This takes advantage of an attribute of the Preg_replace function that, when the matching pattern has an e modifier, is replaced with Eval for a back reference, that is, replacing the variable and executing the corresponding function. That is, Preg_replace will match the substring, passing in the form of an argument to the Rewriteoutput function, rewriteoutput the value returned by the function as the replacement content. (There are several links on the page that will perform several rewriteoutput functions, which is why turning on pseudo-static slightly affects performance)
The problem comes again, pseudo-static is not replaced why is it?
The reason is very simple, because it is in the page output before the replacement, so all the procedures can be done on the hands and feet are floating clouds. The only thing that really works is the link before the output, which is not a pseudo-static substitution rule. Links like/forum.php?mod=viewthread&tid=xx#lastpost are naturally not replaced successfully.
At this point, discuz pseudo-static is how to replace and display the mechanism even if the introduction is complete.
These days, Discuz pseudo-static very good research, and found that their own forum reading function to stick pseudo-static, if so, out of this tutorial paste ....
/forum.php?mod=guide&view=digest Such an address is really not good to see, and then discuz at least x2.5 has not given guidance add pseudo static rules, x3.0 I don't know, not carefully to see
Welcome to visit Http://www.sxwlkj.net Online network technology to provide
Then get to the point .....
1.function_admincp.php//Add 1384 lines to the background interface
$data [' Rulesearch '] [' forum_guide '] = ' guide-{action}-{page}.html '; $data [' Rulereplace '] [' forum_guide '] = ' portal.php?mod=guide&view={action}&page={page} '; $data [' Rulevars '] [' forum_guide '] [' {action} '] = ' ([a-z0-9_\-]+) '; $data [' Rulevars '] [' forum_guide '] [' {page} '] = ' ([0-9]+) ';
2.function_admincp.php Replace URL address rule 1340 line
if (In_array (' forum_guide ', $_g[' setting ' [' Rewritestatus '])) { $data [' Search '] [' forum_guide '] = '/'. $_g[' domain ' [' pregxprw '] [' Forum ']. \?mod\=guide& (amp;)? view\= (\w+) (&page\= (\d+)) \ "([^\>]*) \>/e"; $data [' Replace '] [' forum_guide '] = "rewriteoutput (' Forum_guide ', 0, ' \\1 ', ' \\3 ', ' \\5 ', ' \\6 ')"; }//self-added guided navigation
3. Replacement function plus a guide to judge function_core.php function Rewriteoutput ($type, $returntype, $host)
} elseif ($type = = ' Forum_guide ') {//Added List (,,, $action, $page, $extra) = Func_get_args (); $r = Array ( ' {action} ' = $action, ' {page} ' = $page? $page: 1, );//Add the
4. Add language lang_admincp.php//Add
The final result is the following background
<ignore_js_op>
The final result is the following foreground
<ignore_js_op> Qq20130609171641.jpg (51.15 KB, download number: 5) |
|
Analysis of pseudo-static principle of discuz!