Url rewriting 使用nginx重写多个单独的url
我需要在nginx上重写大量的url(大约250个) 发件人:Url rewriting 使用nginx重写多个单独的url,url-rewriting,nginx,rewrite,Url Rewriting,Nginx,Rewrite,我需要在nginx上重写大量的url(大约250个) 发件人:http://xyzwiki.de/wiki/index.php?title=Article1 收件人:http://wiki.zyx.de/wiki/AlternativeNameForArcticle1 很明显,源代码确实使用了经典url和其他名称,我有一个包含所有源代码和目的地的表 我曾尝试使用基本重定向示例,但没有成功。我认为这可能是因为源URL使用URL参数——但我没有找到解决方案 所以我需要一个映射,在这里我告诉nginx
http://xyzwiki.de/wiki/index.php?title=Article1
收件人:http://wiki.zyx.de/wiki/AlternativeNameForArcticle1
很明显,源代码确实使用了经典url和其他名称,我有一个包含所有源代码和目的地的表
我曾尝试使用基本重定向示例,但没有成功。我认为这可能是因为源URL使用URL参数——但我没有找到解决方案
所以我需要一个映射,在这里我告诉nginx一组源url和它们各自的重写目标。我个人将使用这个工具在php中处理这个问题 这样,如果保存在服务器上的某个地方,下面的代码块将针对每个php调用运行,并设置自动预结束文件以加载它
if ($_SERVER['SCRIPT_NAME'] == '/index.php') {
// only proceed if this is the root index.php file
$title = $_GET['title'];
$urlMap = array (
'article1' => 'alternative1',
'article2' => 'alternative2',
'article3' => 'alternative3',
...
'article250' => 'alternative250'
);
if (array_key_exists($title, $urlMap)) {
// redirect to alternative url
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://wiki.zyx.de/wiki/" . $urlMap[$title]);
exit;
} else {
// unset vars and continue otherwise
unset($title);
unset($urlMap);
}
}