Reputation: 531
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.
Upvotes: 1
Views: 361
Reputation: 785651
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]
Upvotes: 1
Reputation: 7476
Try it like this,
RewriteEngine on
#if you want it to use for sub dir
RewriteBase /subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#below for url which only have view as parameter
RewriteRule ^([\w]+)/([\w]+)$ $1.php?view=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([^/]*)$ users.php?user=$1
RewriteRule ^dev/([^/]*)$ dev.php?type=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/edit/([^/]*)$ /$1.php?view=edit&id=$2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^groups/permissions/([^/]*)$ /groups.php?view=permissions.php&id=$1 [QSA,L]
Upvotes: 1
Reputation: 80
maybe you should copy this file into domain.com/subdir
, but this is not that good, you should think of using a php mvc framework like symfony, it will resolve your problem smoothly, plain php is hard to extend.
Upvotes: 0