This question has already been answered:
Create, I can not figure out how to write a redirect for non-static links, that is, I will take links from the database and redirect them. I have localhost/index.php?id=KMHUd
and I want to hide index.php?id=
so I could just write localhost/KMHUd
. Tell me what you need to register in htaccess?
The script with this question does not work:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} ^(.*)$ RewriteRule .* index.php?id=%1 [L,QSA]
How to make a redirect in order to be able to use the $_SERVER
on the page I do not know.
File index.php:
<?php $ID = $_GET['id']; if($ID) { try{ $db = new PDO("mysql:host=127.0.0.1;port=3306;dbname=mydb", 'admin', 'admin'); $db->query("SET CHARACTER SET utf8"); $query = $db->prepare("SELECT * FROM linktable WHERE Substitution=?"); $query->bindValue(1, $ID, PDO::PARAM_STR); $query->execute(); $res = $query->fetch(); if($res != null) { $link = 'Location: ' . $res['Link']; //echo "<p>" . $res['Link']; //echo "<p>" . $res['Substitution']; $db = null; // echo $link; header($link); } else echo "<p>Not Found!</p>"; }catch(PDOException $e) { echo $e->getMessage(); } $db = null; } ?>
index.php
? You specifiedphp
and.htaccess
tags in your question, but for some reason I see only the code from.htaccess
. - Vismanindex.php
code to the post above. - Max_Advancedheader($link);
set theexit();
. - Visman