D
D
danyfir2020-12-08 16:39:06
htaccess
danyfir, 2020-12-08 16:39:06

How to make a condition in htacces?

Hello! I work on CNC. In general, you need to convert any /shop/catalog?category=kurtki to /shop/catalog/kurtki . It seems that in general I figured out how to do it, individually everything works, but when I write everything together, nothing works. As I understand it, they conflict with each other (maybe I'm wrong). Please help me figure it out.

The general condition "RewriteRule ^(.*)/?$ $1.php [NC]" behaves especially problematic. I don't know much about regular expressions (I know, shame on me), but I beg you to help me figure it out.

It seems to me that each condition needs a selection (type if there is "shop /" in the address, then we do this ...).

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/(.*)/?$ /shop/tovar.php?id=$1 [L,NC]  #меняем shop/tovar.php?id=* на shop/*

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/catalog/(.*)/?$ /shop/catalog.php?category=$1 [L,NC]  #меняем shop/catalog.php?category=* на shop/catalog/*

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ $1.php [NC]  #открываем файл .php, если расширение не введено в адресную строку, т.е. меняем /*.php на просто /*

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-12-08
@danyfir

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/catalog/(.*)$ /shop/catalog.php?category=$1 [L,NC]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^shop/(.*)$ /shop/tovar.php?id=$1 [L]

RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.*)$ $1.php [L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question