1

if i use a link in katalog:

<a href="/katalog/musik">Musik</a>

It opens in the URL:

/katalog/musik/?&kategorie1=musik[NC,L]

and then the page.
But if I open /katalog/musik by myself in the URL the page open too. The other rules are working fine, also with a .

How can I change it, that if I click on a link on a page, that the ?&... doesn't appear.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]

RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+)/([0-9]+) dienstleister.php?id=$3&kategorie1=$1&kategorie2=$2 [NC,L]
RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+) kategorie.php?kategorie1=$1&kategorie2=$2  [NC,L]
RewriteRule ^katalog/([A-Za-z]+) kategorie.php?kategorie1=$1 [NC,L]
4
  • what do you what you link to look like?
    – Dean
    Jul 12, 2019 at 17:01
  • Like /katalog/musik
    – klediooo
    Jul 12, 2019 at 17:51
  • just create a rule for that link
    – Dean
    Jul 12, 2019 at 17:55
  • RewriteRule ^/katalog/musik?$ kategorie.php [NC,L] if the page has a special GET variable add it also
    – Dean
    Jul 12, 2019 at 18:03

2 Answers 2

1

Change order of your rules and also add end anchor in last 3 rules:

RewriteEngine on

RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+)/([0-9]+)/?$ dienstleister.php?id=$3&kategorie1=$1&kategorie2=$2 [NC,QSA,L]
RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+)/?$ kategorie.php?kategorie1=$1&kategorie2=$2  [NC,QSA,L]
RewriteRule ^katalog/([A-Za-z]+)/?$ kategorie.php?kategorie1=$1 [NC,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
5
  • I'm just getting now as URL /katalog/musik/404, but if I remove the 404 in the URL, it shows the right website.
    – klediooo
    Jul 15, 2019 at 19:28
  • 1
    Test in Chrome dev tool with caching disabled and check in Networking tab what are 301/302/404 redirect URLs you get.
    – anubhava
    Jul 15, 2019 at 19:41
  • I used Firefox to test this, there comes the result above. But if I use Chrome the URL is like I wished.
    – klediooo
    Jul 15, 2019 at 19:46
  • 1
    That means you have bad cache in Firefox. Completely clear cache and retest
    – anubhava
    Jul 15, 2019 at 19:50
  • 1
    Oh, doesn't knew that cache affect the URL too. Working now, thx.
    – klediooo
    Jul 15, 2019 at 20:03
0

Using the [QSD] flag causes the query string to be discarded. This flag is available in Apache version 2.4.0 and later.

Add QSD to rewrites flags:

RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+)/([0-9]+) dienstleister.php?id=$3&kategorie1=$1&kategorie2=$2 [NC,QSD,L]
RewriteRule ^katalog/([A-Za-z]+)/([A-Za-z]+) kategorie.php?kategorie1=$1&kategorie2=$2  [NC,QSD,L]
RewriteRule ^katalog/([A-Za-z]+) kategorie.php?kategorie1=$1 [NC,QSD,L]
1
  • Doesn't work, still the same result. The Apache Version ist 2.4.35, but the Server API is Apache 2.0 Handler. Is this relevant?
    – klediooo
    Jul 15, 2019 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.