-2

I want to rewrite my URLs on localhost. First parameter "p" is the page. all other parameters "param1" - "paramX" schould work when I need them. With only one parameter "p" it works every fine. But now I want editing a second parameter in the URL and just want to echo it first. This works too. But when I click on my menupoints, that only use parameter "p" as links, it don´t work right. I get no errors, but parameter "p" do not change, as it should, but "param1" changed and my menu doesn´t open any right site any more. I am a beginner in htaccess und hope you can help me. In the following I post some screenshots

htaccess File

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)$ index.php?p=$1 [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ index.php?p=$1&param1=$2 [NC,L]

Parameter "P" for sites alone works well

Get the second parameter and index.php

Getting and echo the second parameter works too

But clicking on menupoint don´t work any more

Links with a-tag look like <a href = "projcet">Projekt</a> or <a href = "acp">ACP</a>

As you can see, if I click on acp (link with href = "acp") it doesn´t changed the first parameter. It changed the second and the link doesn´t work any more.

Could you help me and could you tell me what I am doing wrong in my the htaccess file?

I tried to change the URL, but it doesn´t work. And I edited the htaccess file multiple times with try and error the last day and this is the best result I got. And the other possibilities from stayoverflow which showed up didn't help me.

Richy2000
  • 3
  • 2
  • 4
    [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551) – shingo Aug 30 '23 at 09:51
  • 3
    Plus the screenshot you linked as "htaccess File", doesn't even actually show that, it's also a screenshot from your browser UI ... – CBroe Aug 30 '23 at 09:53
  • Maybe this will help: https://stackoverflow.com/questions/16388959/url-rewriting-with-php – YetiCGN Aug 30 '23 at 10:31
  • Sorry, i chose the wrong image. I can´t edit a new image. so I put a link into the post. @YetiCGN 1 parameter works fine. – Richy2000 Aug 30 '23 at 11:43
  • `I can´t edit a new image`...why? You should be able to create markdown just the same as the others to put it in, all it needs to make it inline is the `!` in front of it. look at the syntax of the others in the raw question text. – ADyson Aug 30 '23 at 11:47
  • _"so I put a link into the post"_ - that doesn't change the fact that it is _still_ an image you are linking to. Did you completely ignore what the very first comment told you ...? – CBroe Aug 30 '23 at 11:48
  • But also, didn't you read the very first comment above?? Pasting code/data/errors as graphics is very impractical as it can't be copied, searched, re-used in answers etc. It makes it difficult for those who might want to help you. Please [edit] your question to include the code as text and use the [formatting tools](https://stackoverflow.com/help/formatting) to present it nicely, so that it is usable for those who want to help you. The [ask] guide (which is linked from the Ask Question page for your benefit) clearly states that you must not upload this info in picture form. – ADyson Aug 30 '23 at 11:49
  • 1
    P.S. As you're new, please also take the [tour] (as the system recommended you to do when you first created your account, but I can see from the missing badge in your profile that for some strange reason you did not), so that you understand more about how stackoverflow works. These resources exist to help you have a better experience here, so please don't ignore them. Thanks. – ADyson Aug 30 '23 at 11:50
  • Sorry I am not feeling healthy today. I edited the Code from htaccess in code tag. – Richy2000 Aug 30 '23 at 12:10

1 Answers1

0

Links with a-tag look like <a href = "projcet">Projekt</a> or <a href = "acp">ACP</a>

I think there's your problem. You're using directory-relative links in your menu but you seem to use the menu on every page. So if the user is at /project/test, a link to acp will link to /project/acp. If you use an origin-relative link (in this case /acp), it will correctly link to the URL you want. This has more to do with basic understanding of the workings of the HTML tag <a> than with .htaccess.

YetiCGN
  • 739
  • 4
  • 10