Sjef92 Sjef92 - 2 months ago 14
Apache Configuration Question

.htaccess links working, but no GET variables

On one of my websites the .htaccess is working for links, but the php file doesn't detect a GET method.

My .htaccess

ErrorDocument 404 /404
ErrorDocument 500 /500

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^(resources)($|/) - [L]
RewriteRule ^user/([^/]*)$ /users.php?user=$1 [L]
RewriteRule ^dev/([^/]*)$ /dev.php?type=$1 [L]
RewriteRule ^users/([^/]*)$ /users.php?view=$1 [L]
RewriteRule ^users/edit/([^/]*)$ /users.php?view=edit&id=$1 [L]
RewriteRule ^settings/([^/]*)$ /settings.php?view=$1 [L]
RewriteRule ^groups/([^/]*)$ /groups.php?view=$1 [L]
RewriteRule ^groups/edit/([^/]*)$ /groups.php?view=edit&id=$1 [L]
RewriteRule ^groups/permissions/([^/]*)$ /groups.php?view=permissions.php&id=$1 [L]
RewriteRule ^page/([^/]*)$ /page.php?view=$1 [L]


This worked for me on
domain.com
but not anymore on
domain.com/subdir

Not only that, but isn't there a better way to process the get requests rewrite so I don't have to add a rule for every php file that does something with GET requests?

Thank you in advance.

Answer

You need to turn off MultiViews option and you can also merge some of your similar rules into one:

ErrorDocument 404     /404
ErrorDocument 500     /500
Options +FollowSymLinks -MultiViews

RewriteEngine On

RewriteRule ^(resources)($|/) - [L]

RewriteRule ^user/([^/]+)/?$ /users.php?user=$1 [L]

RewriteRule ^dev/([^/]+)/?$ /dev.php?type=$1 [L]

RewriteRule ^(users|settings|groups|page)/([^/]+)/?$ /$1.php?view=$2 [L,QSA,NC]

RewriteRule ^(users|groups)/(\w+)/([^/]+)/?$ /$1.php?view=$2&id=$3 [L,QSA,NC]

# To internally redirect /dir/file to /dir/file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]