Rewrite rule sending to wrong page

0

I have the following rewrites in my htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteRule ^dados/series/([a-z,0-9,A-Z-].+)/?$ dados-series.php?cache=$1 [NC,L]
    RewriteRule ^dados/series/([a-z,0-9,A-Z-].+)/configs/?$ serie-configs.php?serie=$1 [NC,L]
</IfModule>

But for some reason, the rewrite that should be read on the page serie-configs is being sent to the first page, in the dados-series case, what could be causing such an error?     

asked by anonymous 12.05.2017 / 00:21

1 answer

0

Your "group" of [a-z,0-9,A-Z-] does not make sense and the use of .+ all within [...] almost redundant, you have to first learn regex before quitting doing any but it has many examples on the site, especially on regex, see and

The commas within [] seem like you used as a separator, but in regex this does not exists, - within [] should be escaped with \ .

The dot . sign is what caused the failure, because the dot is a meta-character that "matches" with any character, see what happens:

  • See example link

    Your regex takes all rows, with configs and without in the string

Now adjust:

  • See example link

    The correct regex only takes the two lines that do not contain configs

Then adjust to this:

RewriteEngine On

RewriteRule ^dados/series/([a-z0-9A-Z\-]+)/?$ dados-series.php?cache=$1 [NC,L]
RewriteRule ^dados/series/([a-z0-9A-Z\-]+)/configs/?$ serie-configs.php?serie=$1 [NC,L]

And if it still does not work, reverse the order:

RewriteEngine On

RewriteRule ^dados/series/([a-z0-9A-Z\-]+)/configs/?$ serie-configs.php?serie=$1 [NC,L]
RewriteRule ^dados/series/([a-z0-9A-Z\-]+)/?$ dados-series.php?cache=$1 [NC,L]

Note that if the urls are relative to the internal documents then it does not require rewritebase , using it can cause an error, I also removed the <IfModule mod_rewrite.c> because from my point of view if the module is not activated even with IF the site will fail because the links will accuse you of not existing, so it is better that error 500 instead of the person accessing broken pages

    
12.05.2017 / 05:52