Problem in Friendly Url

Asked

Viewed 124 times

1

I have another problem with this line

RewriteRule ^([a-zA-Z-0-9-_]+)$ index.php?controller=estabelecimentos&option=tipo&tipo=$1 [L]

solved a problem but now I tried to create the same line but for another file but always falls into that rule establishments how can I fix it ?

htaccess Financial Network

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^comer$ index.php?controller=comer
RewriteRule ^dormir$ index.php?controller=dormir
RewriteRule ^comprar$ index.php?controller=comprar
RewriteRule ^servicos$ index.php?controller=servicos
RewriteRule ^lazer$ index.php?controller=lazer
RewriteRule ^o-que-visitar$ index.php?controller=o-que-visitar
RewriteRule ^contactos$ index.php?controller=contactos
RewriteRule ^login$ index.php?controller=login
RewriteRule ^([a-zA-Z-0-9-_]+)$ index.php?controller=estabelecimentos&option=tipo&tipo=$1 [L]
RewriteRule ^([a-zA-Z-0-9-_]+)$ index.php?controller=ver_estabelecimento&option=tipo&tipo=$1 [L]

I have on route establishments the url to be provided so http://exemplo.pt/traditional i wanted to create another rule equal but to see the establishment corresponding to traditional category but stay in an equal url http://exemplo.pt/cafe I made a rule equal to establishments, but for the ver_establishment file and always falls under the rule of establishments.

  • Put your .htaccess complete and give an example of URL.

  • I already put up with example

  • @Césarsousa gives the final example you want for this sff url

  • http://exemplo.pt/cafe

  • @Césarsousa The final URL he refers to is the internal one that will load PHP.

  • yes only that instead of loading the ver_establishment file always loads the establishments

  • @Césarsousa What is this "ver_establishment"? You don’t have any of this in your . htaccess.

  • ver_establishment and the file that will show the establishment after the user choose the category in this case establishments I forgot to put the rule I was trying to do already put there

  • loads the same because ajax is the same. Try changing the last line by: Rewriterule p/([a-za-Z-0-9-_]+)$ index.php? controller=ver_establishment&option=type&type=$1

  • but then I have to use the p before the name

Show 5 more comments

1 answer

1


You cannot use twice exactly the same pattern because apache will only consider the first one. You can add a /ver (or something like) at the end of the URL to differentiate the operation.

Ex.:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(comer|dormir|comprar|servicos|lazer|o-que-visitar|login)$ index.php?controller=$1 

RewriteRule ^([a-zA-Z-0-9-_]+)$ index.php?controller=estabelecimentos&option=tipo&tipo=$1 
RewriteRule ^([a-zA-Z-0-9-_]+)/ver$ index.php?controller=ver_estabelecimento&option=tipo&tipo=$1

With this last rule, the URL http://exemplo.pt/[TIPO]/ver will carry index.php?controller=ver_estabelecimento&option=tipo&tipo=[TIPO]

  • So it means you can never use urls without the file name

  • @Césarsousa It is not possible to redirect an equal pattern to different actions. If you really don’t want to use the regular expression there just specify a rule for each different url. The problem with this is that if this content is dynamic you will have to add a new rule for each new item created.

  • yes the site and dynamic but I know a site that uses this way and dynamic example here https://www.zomato.com

  • @Césarsousa This site uses different Urls for different actions. To list restaurants in a category, for example, it uses /restaurants/internacional and to see the item it uses the restaurant name in the URL. There must be at least one difference in the address or apache has no way of knowing what to do.

  • but I don’t notice any difference in the url as it is possible I still haven’t figured out very well

  • @Césarsousa I don’t understand. Which URL are you talking about?

  • They have the url https://www.zomato.com/pt/grande-lisboa/top-restaurants which is the category and then when choosing the establishment is thus https://www.zomato.com/pt/grande-lisboa/nome_do_estabelecimento does not change anything in the url to differentiate in apache

  • 1

    @Césarsousa Yes, but you didn’t quote this in your question. How do you want your URL to look?

  • I want you to stay http://exemplo.pt/nome_do_estabelecimento I apologize for not being able to express myself well. establishment name and the name of the establishment

  • Can you tell me then how I can do this url

  • I think you should use this rule then even setting the file name, but create something like "see-establishment" so it stays practical and optimized.

  • because I know this way solves my problems but the client does not want to use the name of the files just want the name of the establishment or category

  • I just need to know if it’s possible to do it that way ?

  • @Césarsousa To stay this way the list of establishments has have something different in the URL. With two equal rules apache will not know what is what.

  • then this example site as and what they do, make the rule for each one created ?

  • Ready I fixed the prolema always changing anything in the rule now I wanted to create a rule that would give to two different files ?

Show 11 more comments

Browser other questions tagged

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