Reputation: 8702
I'm trying to simply the access to my API
with a .htaccess
file and I'm facing an issue.
For example, what I'd like to achieve is:
User reaches http://localhost/teammngr/user/photos/secrethash
and is automatically redirected to http://localhost/teammngr/user/photos.php?sid=secrethash
.
User reaches http://localhost/teammngr/user/config/secrethash
and is automatically redirected to http://localhost/teammngr/user/config.php?sid=secrethash
.
User reaches http://localhost/teammngr/team/members/secrethash
and is automatically redirected to http://localhost/teammngr/team/members.php?sid=secrethash
.
If the user wants to reach these files directly, it is supposed to be possible.
Moreover, the url http://localhost/teammngr/
will be under a subdomain like http://team.mywebsite.com/
.
So far, I've made the following .htaccess
file, but it keeps throwing a 500
error on my server.
To be clear, this file is not in the root directory but in a sub dir.
Options +FollowSymlinks
RewriteEngine On
RewriteBase /teammngr
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([a-z_]+)/([A-Za-z0-9_-]+)$ /user/$1.php?sid=$2 [L]
RewriteRule ^team/([a-z_]+)/([A-Za-z0-9_-]+)$ /team/$1.php?sid=$2 [L]
Where did I make a mistake ?
Thanks for your precious help.
Upvotes: 1
Views: 46
Reputation: 3299
you can try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /teammngr
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user/([a-z_]+)/([A-Za-z0-9_-]+)$ user/$1.php?sid=$2 [L]
RewriteRule ^team/([a-z_]+)/([A-Za-z0-9_-]+)$ team/$1.php?sid=$2 [L]
Upvotes: 0
Reputation: 785146
RewriteCond
is only applicable to very next RewriteRule
. To avoid repeated RewriteCond
before every rule you can have a separate rule to ignore requests for files and directories. Also remove /
from your target URIs.
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /teammngr/
# ignore requests for files and directories from rules below
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^user/(\w+)/([\w-]+)/?$ user/$1.php?sid=$2 [L,QSA]
RewriteRule ^team/(\w+)/([\w-]+)/?$ team/$1.php?sid=$2 [L,QSA]
Upvotes: 1