2017-02-01 4 views
2

Ich habe einen URL-Verkürzung erstellt, ich benutze eine Rewrite-Regel, aber die Bilder auf meiner Seite werden nicht geladen, wenn ich dies eingeschaltet habe, und dies ist nur ein Problem, wenn ich die Seite zum ersten Mal laden. Wenn ich die Regel entferne, lade die Seite und schalte die Regel dann auf den Bildern fort. Wenn ich jedoch meinen Browser öffne und die Seite mit der Regel lade, werden die Bilder nicht geladen. Kann mir jemand dabei helfen? Hier ist mein Code.Bild wird nicht geladen, wenn RewriteEngine verwendet wird?

index.php

<?php 
    include 'connect.php'; 

    if(isset($_GET['title'])) { 
     $result = $conn->prepare("SELECT * FROM atomly_shortener WHERE id=?"); 
     $result->bind_param("s", $_GET['title']); 
     $result->execute(); 

     $goto = $result->get_result()->fetch_array(); 
     $g = $goto[1]; 
     header("location: $g"); 
    } 
    if(isset($_POST['submit_url'])) { 
    if(substr($_POST['submit_url'], 0, 7) != "http://") { 
     $longurl= "http://".$_POST['long_url']; 
    } else { 
     $longurl=$_POST['long_url']; 
    } 
    $sql = "INSERT INTO atomly_shortener (long_url) VALUES ('$longurl')"; 
    if ($conn->query($sql) === TRUE) { 
    } else { 
     echo "Error: " . $sql . "<br>" . $conn->error; 
    } 
    $sql = "SELECT id, long_url FROM atomly_shortener WHERE long_url='$longurl'"; 
    $result = $conn->query($sql); 
    if($result->num_rows > 0) { 
     // Set session variables 
     $result = $conn->query($sql); 
     if($result->num_rows > 0) { 
      $row = mysqli_fetch_array($result); 
      $long = $row["long_url"]; 
      $id = $row["id"]; 
      $shorturl = $id; 
      $sql = "UPDATE atomly_shortener SET short_url = '$shorturl' WHERE long_url='$longurl'"; 
      if ($conn->query($sql) === TRUE) { 
       //echo "<script type='text/javascript'>alert('$shorturl');</script>"; 
       //echo "<script type='text/javascript'> document.getElementById('shorter').innerHTML = 'hello'; </script>"; 
      } else { 
       echo "Error: " . $sql . "<br>" . $conn->error; 
      } 
     } 
     else { 
     echo "Unknown Error!"; 
     } 
    } 
    else { 
     echo "Error shortening url, please try again!"; 
    } 
    } 
?> 

<DOCTYPE html> 
<html> 
    <head> 
     <link rel="stylesheet" href="styles.css"> 
    </head> 
    <body> 
     <div id = "container"> 
      <img id = "logo" src = "images/atomly_logo.png"></img> 
      <form method="post" action="index.php"> 
       <fieldset class = "cf"> 
        <input id = "url_long" type = "text" class = "shorten-input" placeholder = "Please enter your url..." name="long_url"></input> 
        <input id = "submit_" type = "submit" name = "submit_url" class = "action-btn" value = "SUBMIT"></input> 
       </fieldset> 
      </form> 
      <div id ="shorter"><h1><?php if(isset($shorturl)){ echo "Short URL: localhost:81/atomly/".$shorturl; } ?></h1></div> 
     </div> 
    <body> 
</html> 

.htaccess

RewriteEngine On 
RewriteRule ^([^/]+)/? index.php?title=$1 [L,QSA] 

Das Bild, das nicht auf dieser Linie

<img id = "logo" src = "images/atomly_logo.png"></img> 
+0

Mögliche Duplikate von [Seo Friendly URL css img js funktioniert nicht] (http://StackOverflow.com/questions/31241701/seo-friendly-url-css-img-js-not-working) – starkeen

Antwort

0

Sie benötigen wird geladen Ihre .htaccess Datei zu aktualisieren so:

RewriteEngine On 

RewriteRule !\.(?:jpe?g|gif|bmp|png|tiff)$ index.php?title=$1 [L,QSA] 
+0

Ehrfürchtig, Danke. –

Verwandte Themen