正则表达式.Htaccess重定向
问题描述:
我构建了一个缩短长链接的脚本。一切正常,只是当我访问缩短的链接,我得到正则表达式.Htaccess重定向
错误"Not Found The requested URL /ESrdhPNLMV was not found on this server."
缩短网址有http://example.com/ESrdhPNLMV
格式。 “ESrdhPNLMV”部分作为标题存储在数据库中,作为长url的标题。
当前的.htaccess规则
RewriteEngine on
RewriteRule ^([^\/]+)\/?\/example.com\/?title=$1 [L,QSA]
我从别人的代码,并与regex101.com修改,并结束了与上面的代码。 请问当我访问短链接时,重定向到数据库中存储的url的正确方法是什么?
下面是从数据库中获取URL代码:
if(isset($_GET['title'])){
//select link from database
$result = $db->prepare("SELECT * FROM links WHERE title =?");
$result->bind_param("s",$_GET['title']);
$result->execute();
$goto = $result->get_result()->fetch_array();
$g = $goto[1];
header("Location: $g"); }
ERROR LOG ON:
$goto = $result->get_result()->fetch_array();
即:
PHP Fatal error: Call to undefined method mysqli_stmt::get_result() in
看到上面的错误有一个lin到mysqlnd驱动程序,我用phpinfo()检查并发现驱动程序已启用。所以我在这里做错了什么?
更新: 现在我已经能够解决该错误消息。和去
http://example.com/?title=ESrdhPNLMV
答
你需要把规则改成这样:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ /?title=$1 [L,QSA]
是否通过'http://example.com/标题= ESrdhPNLMV'工作从浏览器? – anubhava
不,我得到了; example.com目前无法处理此请求。 HTTP错误500 –
重命名你的.htaccess并重新测试该URL – anubhava