Я новичок в php и .htaccess и работаю над созданием удобного для пользователя url-shotner.пример: http://www.example.com/AS78654
Я использую .htaccess, чтобы $ _GET переменную ссылки на index.php.это прекрасно работает на локальном хосте, но после загрузки в среде хостинга это не так.страница обновляется сама, когда я нажимаю на ссылку привязки (http://www.example.com/AS78654) на index.php, дайте мне знать, где я ошибаюсь. Спасибо
.htaccess
#Turn Rewrite Engine On
RewriteEngine On
# NC makes the rule non case sensitive
# L makes this the last rule that this specific condition will match
# $ in the regular expression makes the matching stop so that “customblah” will not work
# Rewrite for index.php?link=xxxxxxx
RewriteRule ^([0-9a-zA-Z]+)$ index.php?link=$1 [NC,L]
index.php
<form action="index.php" method="post">
<input type="text" name="long">
<input type="submit" name="submit">
</form>
<?php
// getting the unique code and redirect the visitor
if (isset($_GET['link']))
{
$con =mysqli_connect("localhost","useername","password","url");
$fetch = "SELECT * FROM shotner WHERE shot = '".$_GET['link']."' ";
$records = mysqli_query($con,$fetch);
while($row = mysqli_fetch_array($records))
{
$final_url = $row['longurl'];
header("location:".$final_url);
}
}
// inserting link & new codes into db
extract($_POST);
if(isset($submit))
{
$con = mysqli_connect("localhost","useername","password","url");
$shoturl = strtoupper(substr(md5(uniqid(mt_rand(0,9999))), 25));;
$query ="INSERT INTO shotner(longurl, shot) VALUES('".$long."','".$shoturl."')";
$res = mysqli_query($con, $query);
if($res)
{
echo '<a href=http://'."$_SERVER[HTTP_HOST]".'/url/'.$shoturl.'>http://'."$_SERVER[HTTP_HOST]".'/url/'.$shoturl.'</a>';
}
else
{
echo "problem with query";
}
}
?>