Conflict of conditions in htaccess

Asked

Viewed 95 times

0

Hello I’m starting to try to work with friendly Urls now, so I’m not sure I’m doing the right thing. Here’s the thing: I have a site made totally without the use of htaccess, so it has huge links, I’ve been researching and to modify it totally will take a lot of work, so I’m trying to use the method of rewriting the Urls by htaccess.

My htaccess is as follows:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)-(.*)-(.*)$ index.php?livro=$1&capitulo=$2&versao=$3
RewriteRule ^(.*)-(.*)-(.*)-(.*)$ versiculos.php?livro=$1&capitulo=$2&versiculo=$3&versao=$4

Both the index, and the page verses, are at the root of the directory. The problem is that if I declare only the second condition, it works right as expected, but as I need to put also the condition of the index, the second condition does not work, I think is giving some kind of conflict.

Like I said, I don’t know if I’m doing anything wrong. There would be some way to specify which page each condition will serve ?

1 answer

0

Hello! Try to put the verse page, as well as other pages, inside another directory (in the example below I put inside a sub directory called "pages") and leave only the index in the root directory. Finally, make the necessary changes to your htaccess as shown EXACTLY below.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^versiculos/(.+)/(.+)/(.+)/(.+)$ pages/versiculos.php?livro=$1&capitulo=$2&versiculo=$3&versao=$4 [NC,L]
RewriteRule ^(.+)/(.+)/(.+)$ index.php?livro=$1&capitulo=$2&versao=$3 [NC,L]

OBS1: Note that I used the L flag on every url rewrite that is for a sort of break for when apache finds the rule. In addition I changed the order of the most specific rules, in the case of the rule of versiculos, to the less specific rule, which in the example represents the rule of the index.

OBS2: When Voce invokes the url of verses it should look like : mydeletin/versicles/parametro1/parametro2/parametro3/parametro4/, but this will change later, if you want.

Browser other questions tagged

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