Trying to merge two different .htaccess
blocks.
- for hiding
*.php
extension:
RewriteRule ^([^\.]+)$ $1.php [NC,L]
- for redirecting to specific web is string matched with MySQL row:
RewriteRule ^([a-zA-Z0-9_-]+)$ friendly_url.php?friendly_url=$1
If one works, other gets blocked, for example this way works friendly_url, but it doesn't hide PHP extension:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ friendly_url.php?friendly_url=$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
My php code contains simple query:
$sql = "SELECT * FROM url WHERE friendly_url ='$friendly_url'";
$result = mysqli_query($connection, $sql);
if (!mysqli_num_rows($result) > 0) {
echo "page does not exist";
die();
} else {
echo "page exist";
}
My end goal is to check if file.php
exist, if so redirect to example.com/file
,
then check if in mysql friendly_url exist, if so - redirect to example.com/$friendly_url
else
echo "page does not exist";
Both .htaccess blocks works, but only if one is deleted.