通过创建和编辑.htaccess文件,可以对WordPress网站进行SEO优化。下面是一些.htaccess代码示例,可用于改善WordPress SEO:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
RewriteRule ^old-url$ /new-url [R=301,L]
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType application/javascript "access plus 1 year"
ExpiresByType text/css "access plus 1 year"
</IfModule>
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?your-website.com [NC]
RewriteRule .(jpg|jpeg|png|gif)$ – [NC,F,L]
以上是一些.htaccess代码示例,可以优化WordPress SEO。需要注意的是,修改.htaccess文件时应备份原始文件,以免出现错误。