标签 伪静态 下的文章

Nginx下Xenforo伪静态代码 去掉index.php

折腾了下xenforo,nginx下,涉及到伪静态,需要去掉“index.php?”,由于xenforo在国内这方面的知识并不多,去官方看了下friendurl,使用里面的代码有点小错误提示502错误。

官方的代码

location /xf/ {
try_files $uri $uri/ /xf/index.php?$uri&$args;
index index.php index.html;
}

location /xf/internal_data/ {
internal;
}
location /xf/library/ {
internal;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}


里面的/xf 是路径,打个比方,比如安装在huaihei.com的fx目录下,那么就用上面的代码。但是我在使用上面的代码,502.

我的伪静态代码

于是试着删除了部分,只留下下面的代码。
location /xf/ {
try_files $uri $uri/ /xf/index.php?$uri&$args;
index index.php index.html;
}


于是成功!

操作步骤

1、在这个路径/usr/local/nginx/conf创建xenforo.conf

2、修改/usr/local/nginx/conf/vhost/www.yourwebdomain.conf

帮助:lnmp添加域名会默认生成一个“域名命名的.conf”的文件,比如你的域名是www.hao123.com,那么就是修改/usr/local/nginx/conf/vhost/www.hao123.com.conf

修改参考下图
xenforo conf

3、重启lnmp (命令:/root/lnmp restart)

本文想法有参考官方文档:https://xenforo.com/help/friendly-urls/

discuz X2.5 nginx伪静态规则(含帖子标签)

以前是用htaccess,后来搬到阿里云,使用nginx,需要把规则放到类似website.conf这样的文件,站搬过去好长一段时间,没有注意这个问题,今天捣鼓着顺着别人提供的nginx discuz X2.5规则,写了个支持标签伪静态的规则,这里要特别说明的是,我修改过DZ部分源码,你要参考《Discuz X2.5 标签(tag)伪静态设置方法及规则》做一些修改,才能无误。

- 阅读剩余部分 -

PHPBB论坛伪静态规则写法

不知道使用PHPbb的人多否,前几天折腾一个论坛,用了BB,于是找了下bb的伪静态,发现不是很多~ 仅有的几个看了下生产日期,发现过期了……

为此iFans收集了强人的杰作~

只需要改这四个文件:


1、viewtopic.php
2、viewtopic.php
3、includes/functions_display.php
4、includes/functions.php

分页规则:viewforum-1-0.html -> viewform.php?f=1&start=1 版面两个参数版面id 和分页参数
viewtopic-1-1-1.html -> viewtopic?f=1&t=1&start=1 版面id 帖子id 分页参数
按照规则,在.htaccess里加上下面的代码:

RewriteEngine on

#phpbb重写规则
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^viewtopic-(.+)-(.+)-(.+).html$ viewtopic.php?f=$1&t=$2&start=$3 [L,NC]
RewriteRule ^viewforum-(.+)-(.+).html$ viewforum.php?f=$1&start=$2 [L,NC]

打开viewtopic.php

649行:'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
改为:
//'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_id),
'U_VIEW_FORUM' => "./viewforum". '-' . $forum_id.'-'.'0.html',
567行:$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);

修改为

//$pagination = generate_pagination(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : '')), $total_posts, $config['posts_per_page'], $start);
$pagination = generate_pagination1(append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&t=$topic_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '') . (($highlight_match) ? "&hilit=$highlight" : '')),"./viewtopic". '-' . $forum_id.'-'. $topic_id.'-', $total_posts, $config['posts_per_page'], $start);

打开includes/functions.php

在最后加上这个函数


function generate_pagination1($base_url1,$base_url, $num_items, $per_page, $start_item, $add_prevnext_text = false, $tpl_prefix = '')
{
global $template, $user;

// Make sure $per_page is a valid value
$per_page = ($per_page <= 0) ? 1 : $per_page;

$seperator = '' . $user->lang['COMMA_SEPARATOR'] . '';
$total_pages = ceil($num_items / $per_page);

if ($total_pages == 1 || !$num_items)
{
return false;
}

$on_page = floor($start_item / $per_page) + 1;
$url_delim = (strpos($base_url, '?') === false) ? '?' : ((strpos($base_url, '?') === strlen($base_url) - 1) ? '' : '&');

$page_string = ($on_page == 1) ? '1' : '1';

if ($total_pages > 5)
{
$start_cnt = min(max(1, $on_page - 4), $total_pages - 5);
$end_cnt = max(min($total_pages, $on_page + 4), 6);

$page_string .= ($start_cnt > 1) ? ' ... ' : $seperator;

for ($i = $start_cnt + 1; $i < $end_cnt; $i++)
{
$page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . '';
if ($i < $end_cnt - 1)
{
$page_string .= $seperator;
}
}

$page_string .= ($end_cnt < $total_pages) ? ' ... ' : $seperator;
}
else
{
$page_string .= $seperator;

for ($i = 2; $i < $total_pages; $i++)
{
$page_string .= ($i == $on_page) ? '' . $i . '' : '' . $i . '';
if ($i < $total_pages)
{
$page_string .= $seperator;
}
}
}

$page_string .= ($on_page == $total_pages) ? '' . $total_pages . '' : '' . $total_pages . '';

if ($add_prevnext_text)
{
if ($on_page != 1)
{
$page_string = '' . $user->lang['PREVIOUS'] . '  ' . $page_string;
}

if ($on_page != $total_pages)
{
$page_string .= '  ' . $user->lang['NEXT'] . '';
}
}

$template->assign_vars(array(
$tpl_prefix . 'BASE_URL' => $base_url,
'A_' . $tpl_prefix . 'BASE_URL' => addslashes($base_url1),
$tpl_prefix . 'PER_PAGE' => $per_page,

$tpl_prefix . 'PREVIOUS_PAGE' => ($on_page == 1) ? '' : $base_url . "" . (($on_page - 2) * $per_page.".html"),
$tpl_prefix . 'NEXT_PAGE' => ($on_page == $total_pages) ? '' : $base_url . "" . ($on_page * $per_page).".html",
$tpl_prefix . 'TOTAL_PAGES' => $total_pages,
));

return $page_string;
}

之所以不改原来的函数,是为了留着原始版本,如果将来出问题,可以很简单的恢复,下面同上
打开includes/functions_display.php
加下面的函数:

function topic_generate_pagination1($replies, $url)
{
global $config, $user;

// Make sure $per_page is a valid value
$per_page = ($config['posts_per_page'] <= 0) ? 1 : $config['posts_per_page'];

if (($replies + 1) > $per_page)
{
$total_pages = ceil(($replies + 1) / $per_page);
$pagination = '';

$times = 1;
for ($j = 0; $j < $replies + 1; $j += $per_page)
{
$pagination .= '' . $times . '';
if ($times == 1 && $total_pages > 5)
{
$pagination .= ' ... ';

// Display the last three pages
$times = $total_pages - 3;
$j += ($total_pages - 4) * $per_page;
}
else if ($times < $total_pages)
{
$pagination .= '' . $user->lang['COMMA_SEPARATOR'] . '';
}
$times++;
}
}
else
{
$pagination = '';
}

return $pagination;
}

314行:

'U_VIEWFORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']))

改为:

'U_VIEWFORUM' => "./viewforum". '-' . $row['forum_id']."-0.html")

358行:

'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),

改为:

//'link' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $subforum_id),
'link' => "./viewforum". '-' . $subforum_id.'-0.html',

438行:

$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);

改为:

//$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);
$u_viewforum = "./viewforum". '-' . $row['forum_id'].'-'.$start.'.html';

450行:

$u_viewforum = append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']);

改为:

$u_viewforum = "./viewforum". '-' . $row['forum_id'].'-'.$start.'.html';

586行:

'U_VIEW_FORUM'=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $parent_forum_id))

改为:

'U_VIEW_FORUM' => "./viewforum". '-' . $parent_forum_id.'-0.html')

598行:

'U_VIEW_FORUM'=> append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))

改为:

//'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $forum_data['forum_id']))
'U_VIEW_FORUM' => "./viewforum". '-' . $forum_data['forum_id'].'-0.html')

1095行:

'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),

改为:

//'U_ACTIVE_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $active_f_id),
'U_ACTIVE_TOPIC'=> append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . $active_t_id),

打开viewforum.php
621行:

$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);

改为:

//$view_topic_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", $view_topic_url_params);
$view_topic_url = "./viewtopic".'-' . (($row['forum_id']) ? $row['forum_id'] : $forum_id) . '-' . $topic_id.'-'.$start.'.html';

154行:

'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&start=$start"),

改为:

//'U_VIEW_FORUM'=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&start=$start"),
'U_VIEW_FORUM' => "./viewforum". '-' . $forum_id.'-'.$start.'.html',

306行:

'S_FORUM_ACTION' => append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&start=$start"),

改为:


//'S_FORUM_ACTION'=> append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id&start=$start"),
'S_FORUM_ACTION'=> "./viewforum". '-' . $forum_id.'-'.$start.'.html',

531行:

'PAGINATION'=> generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),

改为:

//'PAGINATION'=> generate_pagination(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')), $topics_count, $config['topics_per_page'], $start),
'PAGINATION'=> generate_pagination1(append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id" . ((strlen($u_sort_param)) ? "&$u_sort_param" : '')),"./viewforum". '-' . $forum_id.'-', $topics_count, $config['topics_per_page'], $start),

645行:

'PAGINATION'=> topic_generate_pagination($replies, $view_topic_url),

改为:

'PAGINATION' => topic_generate_pagination1($replies, $view_topic_url1),

uchome独立使用的伪静态规则

如果你只是安装了UcHome那么上一篇的伪静态规则将对你有参考的作用,但不可直接拿来用。

UcHome直接用的静态规则如下:

1、Htaccess文件内容如下:

# 将 RewriteEngine 模式打开
RewriteEngine on

# Rewrite 系统规则请勿修改
# Collected By weijingtai.com for and uchome

RewriteRule ^/(space|network)-(.+).html$ /$1.php?Rewrite=$2 [L]
RewriteRule ^/(space|network).html$ /$1.php [L]
RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L]

Httpd.ini规则如下,Chinaapp提示此文件需要修改你的UcHome安装目录

[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Collected By weijingtai.com for uchome 1.5
# /home为uchome目录,根据自己安装目录修改

RewriteRule ^/(space|network)-(.+).html$ /$1.php?rewrite=$2 [L]
RewriteRule ^/(space|network).html$ /$1.php [L]
RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L]

点此下载这个伪静态规则

UChome和discuz共用的伪静态规则

UChome 和Discuz共用的伪静态规则文件:

# 将 RewriteEngine 模式打开
RewriteEngine on

# Rewrite 系统规则请勿修改
# Collected By weijingtai.com for discuz 7.0 and uchome
# /home为uchome目录,根据自己安装目录修改

RewriteRule ^/(space|network)-(.+).html$ /$1.php?rewrite=$2 [L]
RewriteRule ^/(space|network).html$ /$1.php [L]
RewriteRule ^/([0-9]+)$ /space.php?uid=$1 [L]

RewriteRule ^archiver/((fid|tid)-[w-]+.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+).html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+).html$ viewthread.php?tid=$1&extra=page%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+).html$ space.php?$1=$2
RewriteRule ^tag-(.+).html$ tag.php?name=$1

不要忘了还有个httpd.ini

[ISAPI_Rewrite]
# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Collected By weijingtai.com for discuz 7.0
#默认uchome装在home目录下,可根据实际情况更改

RewriteRule ^/home/(space|network)-(.+).html$ /home/$1.php?rewrite=$2 [L]
RewriteRule ^/home/(space|network).html$ /home/$1.php [L]
RewriteRule ^/home/([0-9]+)$ /home/space.php?uid=$1 [L]

RewriteRule ^(.*)/archiver/((fid|tid)-[w-]+.html)?*(.*)$ $1/archiver/index.php?$2&$4
RewriteRule ^(.*)/forum-([0-9]+)-([0-9]+).html?*(.*)$ $1/forumdisplay.php?fid=$2&page=$3&$4
RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html?*(.*)$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3&$4
RewriteRule ^(.*)/space-(username|uid)-(.+).html?*(.*)$ $1/space.php?$2=$3&$4
RewriteRule ^(.*)/tag-(.+).html?*(.*)$ $1/tag.php?name=$2&$3

点此下载这两个文件

wordpress的IIS7伪静态 URL Rewrite

wordpress 官方已经内置了 IIS7 URL Rewrite 的支持,但对于中文用户来说,官方内置的伪静态规则不能完好的支持中文tag的问题。虽然可以更改系统文件来解决,但比较麻烦,而且不方便,所以一直没介绍过。现在帖出一个自用的的规则,可以解决wordpress的中文tag的问题。

将下列代码加入到web目录下的web.config文件的<system.webServer>之后即可。