htaccess 重写 url 导致 og 元标记出错
htaccess rewrite url is causing error with og metatags
我的教堂网站有用于描述和图像以及所有爵士乐的 og 元标记。他们都工作得很好。
最近他们要求我从 url 中删除 .php 扩展名,所以我使用 htaccess 来实现。所有的重写似乎都使用它工作正常。
# Turn mod_rewrite on
RewriteEngine On
# Make all requests have the www. in them
RewriteCond %{HTTP_HOST} ^ourchurch\.com
RewriteRule ^(.*)$ http://www.ourchurch.com/ [R=permanent,L]
## don't touch /my_admin_controls URIs
RewriteRule ^my_admin_controls/ - [L,NC]
## don't touch /ourScheduler URIs
RewriteRule ^ourScheduler/ - [L,NC]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
现在,由于某些原因,facebook og 标签无法正常工作。
我查看了调试器,它说存在重定向错误。
有人知道我哪里出错了吗?
...编辑...
og
样本
<head>
<meta charset="UTF-8">
<meta property="og:image" content="http://www.ourchurch.com/images/fblogo.jpg"/>
<meta property="og:title" content="Fall Retreat"/>
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat.php"/>
<meta property="og:site_name" content="Our church .....etc etc"/>
<meta property="og:description" content="Come for fellowship...etc etc."/>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen" />
<title>Retreat Registration</title>
</head>
我认为这是因为您在 .htaccess
中使用重定向来删除扩展名,即 R 标志,试试这个代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
此外,根据您的元标记代码,您拥有:
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat.php"/>
应该是:
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat"/>
因为您已经进行了重定向以删除 .php
,所以 Facebook 出现重定向循环,无法访问该页面。
参考文献:
我的教堂网站有用于描述和图像以及所有爵士乐的 og 元标记。他们都工作得很好。 最近他们要求我从 url 中删除 .php 扩展名,所以我使用 htaccess 来实现。所有的重写似乎都使用它工作正常。
# Turn mod_rewrite on
RewriteEngine On
# Make all requests have the www. in them
RewriteCond %{HTTP_HOST} ^ourchurch\.com
RewriteRule ^(.*)$ http://www.ourchurch.com/ [R=permanent,L]
## don't touch /my_admin_controls URIs
RewriteRule ^my_admin_controls/ - [L,NC]
## don't touch /ourScheduler URIs
RewriteRule ^ourScheduler/ - [L,NC]
## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]
现在,由于某些原因,facebook og 标签无法正常工作。 我查看了调试器,它说存在重定向错误。
有人知道我哪里出错了吗?
...编辑... og
样本<head>
<meta charset="UTF-8">
<meta property="og:image" content="http://www.ourchurch.com/images/fblogo.jpg"/>
<meta property="og:title" content="Fall Retreat"/>
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat.php"/>
<meta property="og:site_name" content="Our church .....etc etc"/>
<meta property="og:description" content="Come for fellowship...etc etc."/>
<link rel="stylesheet" href="css/main.css" type="text/css" media="screen" />
<title>Retreat Registration</title>
</head>
我认为这是因为您在 .htaccess
中使用重定向来删除扩展名,即 R 标志,试试这个代码:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]
此外,根据您的元标记代码,您拥有:
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat.php"/>
应该是:
<meta property="og:url" content="http://www.ourchurch.com/fall_retreat"/>
因为您已经进行了重定向以删除 .php
,所以 Facebook 出现重定向循环,无法访问该页面。
参考文献: