dimasdmm
dimasdmm

Reputation: 328

htaccess rewrite does not work in some pages

.htaccess file:

I have the following htaccess file (it's very short):

RewriteEngine on
Options +FollowSymLinks
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_]+)/?$ index.php?page=$1 [L]

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9_]+)/(.+)/?$ index.php?page=$1&params=$2 [L]

I think is easy to understand it: if a file doesn't exists, then the url is rewrited.

The problem:

An "error" folder or file doesn't exists so it should be rewrited. However, when I try to access to url.local/error/404 don't works, but url.local/error works.

Maybe a problem with Apache?

Edit:

Summary:

Upvotes: 0

Views: 56

Answers (1)

anubhava
anubhava

Reputation: 785246

Maybe a problem with Apache?

No there is no Apache problem. Issue is that your regex is not matching / but your input has one.

Have it this way:

RewriteEngine on
Options +FollowSymLinks
RewriteBase /

RewriteCond %{SCRIPT_FILENAME} -d [OR]
RewriteCond %{SCRIPT_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^(\w+)/(.+)/?$ index.php?page=$1&params=$2 [L]

RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]

Upvotes: 1

Related Questions