andreaem
andreaem

Reputation: 1655

.htaccess handling two different pages

I got two pages that handle the params and display relative pages, first is the auth route and default route.

http://example.com/auth/login
http://example.com/dashboard

First is handled by page auth.php and param page (EG: http://example.com/auth.php?page=login). The second is handled by index.php and param page (EG: http://example.com/index.php?page=dashboard).

I've made the .htaccess file using an online generator, It's something like:

RewriteEngine On
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
RewriteRule ^auth/([^/]*)$ /auth.php?page=$1 [L]

But this cause Error 500, commenting the second line I'm able to reach the auth page with the login param.

Apache2 error.log wrote only this, related to server start:

[Thu Jan 26 20:31:04.795013 2017] [mpm_prefork:notice] [pid 7163] AH00163: Apache/2.4.7 (Ubuntu) PHP/5.5.9-1ubuntu4.20 configured -- resuming normal operations
[Thu Jan 26 20:31:04.795100 2017] [core:notice] [pid 7163] AH00094: Command line: 'apache2'

Upvotes: 0

Views: 91

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You have to exclude the destination you are rewriting to otherwise you will get a rewrite loop error since the pattern ([^/]+) also matches /index.php . So change your first rule to this :

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

Upvotes: 1

Related Questions