我已经制作了一个网址缩短器应用程序,但似乎无法在.htaccess周围工作以确实缩短网址。(我正在使用xampp)
我的域名是http:// localhost / smd我希望用户能够在smd http:// localhost / smd / code之后添加7位代码并将其重定向到他们的页面,我当前的.htaccess代码如下:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^[a-zA-Z0-9_{7}]*$ redirect.php?shortened=$1 [L]
这会将用户重定向到我的smd目录中的另一页,而不是正确的页面。提前致谢!
我的重定向文件:
<?php
include_once './class/Short.php';
date_default_timezone_set('Europe/Athens');
if(isset($_GET['shortened'])) {
$short = new Short();
$code = $_GET['shortened'];
$short->shortened = $code;
$short->getOneUrlByShort();
$expire = $short->getExpiryFromShortened($code);
$comp = (date('Y-m-d H:i:s')<=$expire['expiry_date']);
$enabled = $short->is_enabled;
if ($url = $short->getUrl($code) And $comp And $enabled == 1) {
$redirect = $url['original'];
header("Refresh: 3;".$redirect);
die();
}else if($url = $short->getUrl($code) And !$comp And $short->renewable == 1 And $enabled == 1){
session_start();
$short->renewable = 0;
$newRenewVal = $short->renewable;
$newExpiration = strtotime('+'.$short->active_period.' minutes');
$formattedExpi = date('Y-m-d H:i:s', $newExpiration);
$original = $url['original'];
$_SESSION['original'] = $original;
$_SESSION['expiration_date'] = $formattedExpi;
$short->renewUrl($code, $formattedExpi, $newRenewVal);
header('Location: http://localhost/smd/expiredAndRenew.php');
}else {
header('Location: http://localhost/smd/urlExpired.php');
}
}
?>
我当前的目录如下所示1
使用您显示的示例,您可以尝试以下操作。在测试URL之前,请确保清除浏览器缓存。而且,这只是简单地smd
获取了uri之后的所有内容(启用了ignorecase),并将其作为查询字符串传递给您的redirect.php。如果您要在smd之后查找文本的特定字符串/匹配项,请在此部分让我们更清楚地了解。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_]{7})/?$ redirect.php?shortened=$1 [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句