Rewrite sending to wrong page

Asked

Viewed 167 times

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 front page, in case dados-series, what could be causing such error?

1 answer

0


Your "group" of [a-z,0-9,A-Z-] makes no sense and the use of .+ all that is inside [...] almost redundant, have to learn first regex before leaving doing anything friend, not wanting to sound bad, but there are many examples on the site, mainly about regex, see and

The commas inside the [] looks like you used it as a separator, but in regex it nay exists, the - within [] must be "escaped" with bar \.

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

Now adjust:

So adjust for 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 doesn’t 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 related to the internal documents then you do not need to rewritebase, use it can cause acidendetes, 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 that do not exist, then it is better than to error 500 instead of the person accessing broken pages

  • I’m trying to learn regex, so I’m testing in many ways, thanks for the suggestions.

Browser other questions tagged

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