【发布时间】:2009-10-31 09:00:00
【问题描述】:
我正在编写一个 url 更短的脚本。 它位于http://mini.ample.se/ 短 URL 类似于 http://mini.ample.se/[abc..]
我的 .httaccess 文件看起来像这样
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteOptions MaxRedirects=1
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9_-]+)$ redirect.php?alias=$1 [L]
</IfModule>
当我与 ex 一起尝试时。 mini.ample.se/a 我收到“未指定输入文件”错误。 我知道这与重定向有关,但没有找到我的 redirect.php 文件,但我不确定是什么。
redirect.php 文件看起来像这样
$alias = trim(mysql_real_escape_string($_GET['alias']));
if (!preg_match("/^[a-zA-Z0-9_-]+$/", $alias)) {
header("Location: ".SITE_URL, true, 301);
exit();
}
if (($url = get_url($alias))) {
header("Location: $url", true, 301);
exit();
}
header("Location: ".SITE_URL, true, 301);
谢谢!
【问题讨论】:
-
不应该是
/redirect.php?...加上斜杠吗? -
我也是这么认为的,但是在我的服务器上,我遇到了一个奇怪的问题,即它只有在没有前导斜杠的情况下才能工作!仍然无法弄清楚为什么:S
标签: php mod-rewrite url-rewriting