目前,我的网站设置为将.php重定向到非php版本。 问题是当我检查时,它为两个页面都发出"200 OK",我知道谷歌不行。
我想 301 将.php页面重定向到非 php。 这是同一页面,我已经向该页面添加了规范链接,反映了非.php页面。
如何设置 301? 我目前正在使用以下代码处理使用 .htaccess 定向到非.php页面.php:
# Remove filename extension
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^'.]+)$ $1.php [QSA,NC,L]
</IfModule>
任何想法如何将 200 OK 解析为 301 重定向.php页面(请注意它们是同一页面)?
您需要一个额外的规则:
# Remove filename extension
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# To externally redirect /dir/abc.php to /dir/abc
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+(.+?)'.php['s?] [NC]
RewriteRule ^ /%1 [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [QSA,NC,L]
</IfModule>
将此规则放在现有规则之前。
这会从外部将所有.php
文件重定向到非.php
版本。因此,谷歌不会索引您的.php
文件。