2016-12-05 65 views
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'); 
    } 
}?> 
+2

服务器是否使用Apache并启用了mod_rewrite? –

+0

是它的启用@MagnusEriksson –

+0

顺便说一下......你是大开[SQL注入(http://php.net/manual/en/security.database.sql-injection.php),并应真正使用[预处理语句](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php),而不是串联你的查询。特别是因为你甚至不逃避用户输入 –

回答

0

如在聊天室讨论,有部署到之前的一些意想不到的错误,你的生产服务器。

尽管识别和修正上述问题,你仍然得到404错误,表示在重写规则的问题。

下面的规则应该工作。你只需要这个。不需要2条规则。

RewriteRule ^([a-zA-Z0-9_-]+)\/?$ index.php?r=$1 
相关问题