user3045185
user3045185

Reputation: 49

php include and htaccess

I have index.php file with:

<ul>
 <li><a href="/">home</a></li>
 <li><a href="index.php?id=1">Offer</a></li>
 <li><a href="index.php?id=2">Contact</a></li>
</ul>

<?php
   switch ($id) {
    case '1':
       include 'silnik/oferta.php';
       break;
    case '2':
       include 'silnik/kontakt.php';
       break;

    default:
       echo "<p>brak strony</p>";
       break;
  }
?>

And i want to change index.php?id=1 to /offer with .htaccess

I have in .htaccess

RewriteEngine On 
RewriteRule ^([^/.]+)/?$ /index.php?id=$1

And this doesn't work. Pls help ;)

Upvotes: 0

Views: 153

Answers (2)

Ronald Swets
Ronald Swets

Reputation: 1667

You have to do 3 things:

  1. change your links: <a href="/offer"></a>

  2. Make case statements in switch in the desired strings

  3. Rewrite:

    RewriteEngine On 
    RewriteRule ^(.+)/?$ /index.php?id=$1

Upvotes: 1

Nikolas Sumrak
Nikolas Sumrak

Reputation: 110

RewriteEngine On 
RewriteRule ^([0-9]+)/?$ /index.php?id=$1

OR

RewriteEngine On 
RewriteRule ^(.*)/?$ /index.php?id=$1

Upvotes: 0

Related Questions