1
我已经在用户把长的URL文本字段,当用户点击提交按钮,它在数据库中插入长的URL,并显示简短的URL shortner码用户的URL,这对我的本地主机来说是完美的。URL Shortner代码工作在本地主机上正常,但没有在网站上
但是当我上传在网上它不工作。虽然数据在线插入数据库并显示短网址,但是当我在地址栏中输入网址时,它显示The Site Cant Be Reached server DNS address could not be found.
。 我认为它与我的.htaccess文件有关。
这是我的.htaccess文件:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?r=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?r=$1
这是我的index.php文件:
<?php
include 'config.php';
if(isset($_GET['r']) || !empty($_GET['r']))
{
$url_id = $_GET['r'];
$sql = "SELECT long_url FROM url_shortner WHERE url_id = '$url_id'";
$result = mysqli_query($con,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
if(mysqli_num_rows($result) == 1)
{
$l_url = $row['long_url'];
header('Location:' .$l_url);
}
else
{
header('Location: index2.php');
}
}?>
服务器是否使用Apache并启用了mod_rewrite? –
是它的启用@MagnusEriksson –
顺便说一下......你是大开[SQL注入(http://php.net/manual/en/security.database.sql-injection.php),并应真正使用[预处理语句](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php),而不是串联你的查询。特别是因为你甚至不逃避用户输入 –