【发布时间】:2017-01-05 14:50:20
【问题描述】:
有人像这样链接到我的一个网站:
http://example.com/?p=contactus
?p=contactus 不应该在那里。
如何在.htaccess 中捕获?p=contactus 并将其重定向到http://example.com,或者如何在php 中捕获它?
$_REQUEST['p'] 在 php 中返回一个空字符串,我通常使用的 $_REQUEST['page'] 也是如此(我使用漂亮的 URL)。
由于$_REQUEST['page'] 返回一个空字符串,因此链接会退回到我的 index.php;但是,我想避免 Google 认为我有重复的页面。
【问题讨论】:
-
htaccess 中是否已有重写规则?如果您的链接是
/?p=contactus,那么$_REQUEST['p']不应为空,除非您在Web 服务器中有东西正在重写URL。无论哪种方式,查询字符串参数都不应该自然地影响您所在的页面。 -
我在 .htaccess 中有这些: RewriteRule ^([^/.]+)$ /index.php?page=$1 [L] RewriteCond $1 !(\.(png|ico|css) |index\.php)$ RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index.php? [L]