url friendlies category subcategory

Asked

Viewed 200 times

0

With the category works more as I put the subcategory too?

produtos/nome-categoria/nome-subcategoria


<IfModule mod_rewrite.c>

RewriteEngine On
    #aqui criamos uma condição para que os arquivos sejam ignorados nas regras abaixo
    RewriteCond %{REQUEST_FILENAME} !-f
  #aqui criamos uma condição para que diretórios sejam ignorados nas regras abaixo
    RewriteCond %{REQUEST_FILENAME} !-d
    #aqui definimos onde começa a base das regras

    #fix rules
    RewriteRule ^pagina-inicial/?$ index.php [NC,L]
        #RewriteRule ^produtos/(.*)$ categorias.php?id_categoria=$1 [NC,L]
   RewriteRule ^produtos/(.*)$ categorias.php?id_categoria=$1&nome_categoria=$2 [NC,L]
 RewriteRule ^produtos/(.*)$ subcategorias.php?id_subcategoria=$1&nome_categoria=$2 [NC,L]
        </IfModule>
  • Does this rule work for both? products/name-category and products/name-category/name-subcategory

2 answers

0

If you only have a Search Script in the tables, remove the previous rules and leave only this:

RewriteRule ^produtos/categoria/(.*)/subcategoria/(.*)$ categorias.php?id_categoria=$1&id_subcategoria=$2 [NC,L]

Example of url call:

produtos/categoria/id-da-categoria/subcategoria/id-da-subcategoria

If you have two Search Scripts, one for category and one for subcategory, leave these two rules:

RewriteRule ^produtos/categoria/(.*)$ categorias.php?id_categoria=$1 [NC,L]
RewriteRule ^produtos/subcategoria/(.*)$ subcategorias.php?id_subcategoria=$1 [NC,L]

Example of url call by category:

produtos/categoria/id-da-categoria

Example of calling url by subcategory:

produtos/subcategoria/id-da-subcategoria
  • was right valeuu

  • Guy did so and did not work Rewriterule products/(.)$ categories.php? id_categoria=$1 [NC,L] Rewriterule products/(.)/(.*)$ subcategories.php? id_categoria=$1&id_subcategory=$2 [NC,L]

  • products/name-category works products/name-category/sub-category does not work

  • @Wagnermartinsbodyboard you have to delete the previous rules and leave only this one of the answer. The same is already for categories and subcategories.

  • Do you have two search scripts right? "categories.php" and "subcategories.php" ?

  • yes that’s right products/id-of-category products/id-of-category/id-of-subcategory

  • I made a new edition in the reply.

Show 2 more comments

0

that’s how it works

category/name-category

subcategories/name-category/name-subcategories

RewriteRule ^categorias/(.*)$ categorias.php?id_categoria=$1 [NC,L]
RewriteRule ^subcategorias/(.*)/(.*)$ subcategorias.php?id_categoria=$1&id_subcategoria=$2 [NC,L]

But I wouldn’t be able to stay like this?

produtos/nome-categoria
ptosutos/nome-categoria/nome-subcategorias

I did it and it didn’t work

RewriteRule ^categorias/(.*)$ categorias.php?id_categoria=$1 [NC,L]
    RewriteRule ^subcategorias/(.*)/(.*)$ subcategorias.php?id_categoria=$1&id_subcategoria=$2 [NC,L]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.