伪静态(pseudo-static)是指通过服务器配置将动态网页(如 .php
文件)以静态网页(如 .html
文件)的形式展示给用户。这样做可以提高网站的SEO优化,使URL更加友好,同时也能减少服务器的负载。
.htaccess
文件进行配置。假设你有一个动态页面 article.php?id=123
,你想将其转换为 article/123.html
的形式。
mod_rewrite
模块。.htaccess
文件,添加以下内容:RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^article/([0-9]+)\.html$ article.php?id=$1 [L]
假设你有一个动态页面 article.php?id=123
,你想将其转换为 article/123.html
的形式。
nginx.conf
或 default.conf
),添加以下内容:server {
listen 80;
server_name example.com;
location / {
root /var/www/html;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~* ^/article/([0-9]+)\.html$ {
rewrite ^/article/([0-9]+)\.html$ /article.php?id=$1 last;
}
}
原因:
mod_rewrite
)。.htaccess
或 Nginx 配置文件路径错误。解决方法:
.htaccess
或 Nginx 配置文件路径是否正确。原因:
canonical
标签。解决方法:
canonical
标签,指向首选的URL形式。<link rel="canonical" href="https://example.com/article/123.html" />
希望这些信息对你有所帮助!如果有更多具体问题,欢迎继续提问。
领取专属 10元无门槛券
手把手带您无忧上云