WordPress固定链接

WordPress是一个简单、易用且注重美学的博客程序,而修改固定链接设置不但可以让URL更加美观,对SEO也非常友好,所以大多数人都会选择修改固定链接。直接修改固定连接有可能会导致文章页的404错误,所以需要提前设定好rewrite。

幸好这个过程并不难,这里列举出了最常用的三种Web服务器的修改方法。

Apache2

通过简单的修改.htaccess,就可以解决固定链接的设置:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} ^wp-content.*
RewriteCond %{REQUEST_FILENAME} ^wp-admin.*
RewriteCond %{REQUEST_FILENAME} ^wp-include.*
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Nginx

Nginx也一样简单,找到对应站点的配置文件,加入下面一段配置:

location / {
    # This is cool because no php is touched for static content.
    # include the "?$args" part so non-default permalinks doesn't break when using query string
    try_files $uri $uri/ /index.php?$args;
        }

Lighttpd

''url.rewrite = (
    "^/(wp-.+).*/?" => "$0",
    "^/(sitemap.xml)" => "$0",
    "^/(xmlrpc.php)" => "$0",
    "^/(.+)/?$" => "/index.php/$1"
)''

发表评论

电子邮件地址不会被公开。 必填项已用*标注