K
K
Kirill Rezanov2020-12-10 16:03:08
htaccess
Kirill Rezanov, 2020-12-10 16:03:08

How to properly parse a link in htaccess?

Hello everyone, I need to make a link like shop/lot/1(any number)
I write in .htaccess:
RewriteRule ^/lot/([0-9]+)/?$ ?lot=$1 [NC,L]
But when I go to a link like shop/lot/1, I get a 500th error
. What am I doing wrong? I climbed the Internet and articles on this topic, redid it a bunch of times, but it doesn’t work, maybe something is wrong?
.htaccess code

RewriteEngine On

RewriteBase /

RewriteRule ^/product/([0-9]+)/?$ ?product=$1 [NC,L]
RewriteRule ^/lot/([0-9]+)/?$ ?lot=$1 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2020-12-12
@shambler81

RewriteRule ^lot/([0-9]{1,})$ /\?lot=$1 [NC,L]
also don't forget that GET is not part of RewriteRule and for example the same ? physicists could not be divided in it
if you have such a url with a question at the end, then

RewriteCond %{QUERY_STRING} (?:^|&)\$(?:$|&)
RewriteRule ^lot/([0-9]{1,}))/$ /\?lot=$1 [L,R=301]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question