欢迎来到HELLO素材网! 南京网站制作选择顺炫科技
丰富的DIV CSS模版、JS,jQuery特效免费提供下载
当前位置:主页 > 建站教程 > CMS教程 >

wordpress网站linux和win主机URL伪静态设置方法详解

发表于2019-04-21 03:02| 次阅读| 来源网络整理| 作者session

摘要:wordpress网站linux和win主机URL伪静态设置方法详解

wordpress网站linux和win主机URL伪静态设置方法详解

做伪静态是可以更好的利于网站的SEO优化。

目前大局部网站的搭建都是采用动态网页技术完成的,但是现阶段的搜查引擎对于动态的网站抓取效果并不是很好,所以你常常会听到说搜查引擎不青睐动态的链接,也就是在url中带有“?”的网址,那么怎样修正这种动态的url格式呢?

普通咱们采用的方法是url伪静态设置,就是让链接看起来像是静态的,比如xxx.com/1.html这种格式,wordpress搭建的网站完成伪静态有两种不同的情况,和咱们利用的空间有很大的关系,linux或unix系统的服务器中可以很好的完成这种伪静态的效果,然而windows系统的IIS中设置伪静态会在后面加上index.php,所以无奈完成真正的伪静态性能,下面分别演示这两种空间的完成方法:

linux/unix主机的伪静态完成方法:
1、进入wordpress网站后台依次 》设置 》固定衔接;
2、抉择自定义,填写格式为:/%post_id%.html 即可,如下图:

伪静态设置

这样就可能把文章的格式修正为 xxx.com/123.html 的格式了,假设你想让你的链接看起来更有层次感,可能利用以下格式,让链接现属于分类目录,然后再显示文章ID地址:

/%category%/%post_id%.html

win主机的伪静态完成方法:

win主机下的wordpress文章的链接都是类似的链,

中间的index.php同样显著

这里引见两种方法

第一种:用404.php完成伪静态
1、进入WP后台,【设置】–【固定衔接】里面,先把固定衔接抉择自定义,设置成/%post_id%.html。
2、新建个404.php页面复制下面的404.php页面代码保存后用FTP上传到网站根目录下,然后在虚构主机控制面板里面修正404跳转页面为刚才上传的404.php,这样就可能完成伪静态了。

404.php页面中退出代码如下:

<?php
// This is the default file for the site. Usually index.php
$default = ‘index.php’;

// The name of this file.
// Set this value for the URL in Custom Error Properties of your website in IIS.
// Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
// 404 & 404;2 & 404;3 > URL (Requires a ‘/’ prefix in IIS).
$thisfile = ’404-handler.php’;

$_SERVER['ORIG_PATH_TRANSLATED'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_TRANSLATED']);
$_SERVER['SCRIPT_FILENAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_FILENAME']);
$_SERVER['ORIG_PATH_INFO'] = str_replace($thisfile, $default, $_SERVER['ORIG_PATH_INFO']);
$_SERVER['SCRIPT_NAME'] = str_replace($thisfile, $default, $_SERVER['SCRIPT_NAME']);
$_SERVER['PHP_SELF'] = str_replace($thisfile, $default, $_SERVER['PHP_SELF']);
$_SERVER['PATH_INFO'] = false;

$qs =& $_SERVER['QUERY_STRING'];
$ru =& $_SERVER['REQUEST_URI'];
$pos = strrpos($qs, ‘://’);
$pos = strpos($qs, ‘/’, $pos + 4);
$_SERVER['URL'] = $ru = substr($qs, $pos);
$qs = trim(stristr($ru, ‘?’), ‘?’);

// Required for WordPress 2.8+
$_SERVER['HTTP_X_ORIGINAL_URL'] = $ru;

// Fix GET vars
foreach ( $_GET as $var => $val ) {
if ( substr($var, 0, 3) == ’404′) {
if ( strstr($var, ‘?’) ) {
$newvar = substr($var, strpos($var, ‘?’) + 1);
$_GET[$newvar] = $val;
}
unset($_GET[$var]);
}
break;
}
include($default);
?>

第二种:首先你的主机要装Rewrite 组件,如今国内很多WINDOWS主机都有装这个了。

利用方法:先在本地新建一个 txt 文本文件,把名字重命名为 httd.ini,然后复制下面的代码粘贴到你新建的 httd.ini 文件中保存,间接用FTP上传到你的网站的根目录。然后去WP后台设置固定衔接:/%post_id%.html

httpd.ini 中退出如下代码如下:

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600
RepeatLimit 32
# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP
# Rules to ensure that normal content gets through

RewriteRule /sitemap.xml /sitemap.xml [L]
RewriteRule /favicon.ico /favicon.ico [L]
# For file-based wordpress content (i.e. theme), admin, etc.
RewriteRule /wp-(.*) /wp-$1 [L]
# For normal wordpress content, via index.php
RewriteRule ^/$ /index.php [L]
RewriteRule /(.*) /index.php/$1 [L]

异样也可能完成伪静态,相对而言,第二种方法更好。
假设用了第二种方法导致百度地图链接打不开请减少以下两句代码:

RewriteRule /sitemap.html /sitemap.html [L]
RewriteRule /sitemap_baidu.xml /sitemap_baidu.xml [L]

第三种模式:另外一个比较详细的写法,假设用第二个有成绩,可能尝试这个

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Protect httpd.ini and httpd.parse.errors files
# from accessing through HTTP