0

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 ;)

1
  • 1
    There is no mapping from the slug "offer" to the id "1". So you either have to change your switch-statement or add a rewrite-rule for each slug/id-combination. Btw "it doesn't work" adds no information as to what is happening and what you are expecting to happen. With the information you're providing we have to do some guesswork which invariably leads to wrong answers. Commented Dec 13, 2013 at 8:24

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

so i change my link to <a href="/offer"></a>, change my chase to case 'offer'and add your code to htaccess and it doesn't work
Off course you will need $id filled with the $_GET['id'] parameter... but i assumed you already had that :)
switch($_GET['id']), case "offer": - ?
Yes, since $id is not automaticly the id parameter in the ULR
0
RewriteEngine On 
RewriteRule ^([0-9]+)/?$ /index.php?id=$1

OR

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.