Hej
Jeg forsøger at lave clean URL til min side, og kan ikke rigtig få det til at virke, da jeg ikke har nok viden omkring dette område.
jeg vil gerne ændre min URL fra at se sådan her ud
- article.php?title=bearattack
til at se sådan her ud
- article/bearattack
min htaccess ser sådan her ud:
# Turn Rewrite Engine On
Options +FollowSymLinks
RewriteEngine on
# NC makes the rule non case sensitive
# L makes this the last rule that this specific condition will match
# $ in the regular expression makes the matching stop so that "customblah" will not work
# Rewrite for index.php
RewriteRule ^Home index.php [NC,L]
# Rewrite for article.php
#RewriteRule ^Article article.php&title=$1 [L,QSA]
#RewriteCond %{QUERY_STRING} ^title=([a-zA-Z0-9_-]+)$
#RewriteRule ^article.php$ /%1/? [R=301]
#RewriteRule ^pages/article.php$ /title=%1?
Jeg har brugt en del tid på at finde en løsning men uden held, håber der er en venlig sjæl der vil give mig en hånd.
for at i bedre kan hjælpe mig, sender jeg også lige de 2 andre filer:
INDEX.PHP
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>news</title>
- </head>
- <body>
-
- <?php
-
- $Attack = 'Bear Attack';
- $Killed = 'Bear Killed In Traffic Accident';
- $Child = 'Bear Save Child';
- $Drowning = 'Bear Save Cat From Drowning';
- $articles = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minus in, voluptatem eveniet tempora rerum tenetur, nisi pariatur. Eius sequi, cumque. Quam, sit quidem repellendus! At et nisi quia quasi excepturi doloremque quis hic asperiores iure dignissimos alias blanditiis vitae soluta voluptatibus harum quibusdam, eligendi. Reiciendis, deleniti laboriosam dolorem nihil iusto ipsum saepe, soluta laborum facere cum quae, aliquam sint harum.<br><br>';
-
- $titles = array($Attack, $Killed, $Child, $Drowning);
-
- echo '<div class="row">
- <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">';
- foreach($titles as $title)
- {
- echo '<article>
- <div class="panel-group">
- <div class="panel panel-article-border">
- <div class="panel headerColer"><h4>' . $title . '</h4></div>
- <div class="panel-body">' . $articles . '<a href="article.php?title=' . $title . '">Read more...</a></div>
- </div>
- </div>
- </article>';
- }
- echo '</div>';
- ?>
-
-
- </body>
- </html>
ARTICLE.PHP
- <a href="home">Home</a>
- <?php
-
- $title = $_GET['title'];
-
- $article = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint magnam quam praesentium distinctio nihil fugiat quo molestias eum, aliquid ratione! Praesentium veritatis voluptatem illum ipsum odit aut, sint. Totam saepe, cupiditate et possimus officia modi, ipsa ab provident, porro deserunt delectus ea eveniet. Voluptas dolorum pariatur odio iusto doloremque qui.';
-
-
- echo '<div class="row">
- <div class="col-lg-8 col-md-8 col-sm-8 col-xs-12">
- <article>
- <p>
- <h2>' . $title . '<hr class="hr"></h2>
-
- ' . $article . '
- </p>
- </article>
- </div>';
-
- ?>