Search code examples
.htaccessapache2server-error

mod_rewrite get variable returns Server errors 500


What i'm trying to do is make the link show like this

http://api.example.com/users/useridhere/

Whenever I try to put in the rewrite it gives me a Server Error.

Here is my current code

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^\.]+)$ index.php?id=$1 [NC,L] DirectoryIndex index.php?id=Nobody

If anybody could point out what I did wrong or post a fix I will appreciate that.


Solution

  • If I'm understanding correctly, you're wanting to request and see this in the browser:
    http://api.example.com/users/useridhere/

    But display the contents of:
    http://api.example.com/index.php?id=useridhere

    If this is accurate, then maybe something like this in your [docroot]/.htaccess:

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^users/([\w-]+)$ index.php?id=$1 [NC,L]