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),而不是串聯你的查詢。特別是因爲你甚至不逃避用戶輸入 –