I would like to know how Drupal handles clean URLs without getting a redirection 302 response.

When you have clean URLs enabled, the ?q=123 part of the link goes to /my-node-title and you don't get a 302 redirect but a clean 200 response.

My question is about the code that enables this, and not about how to sort things from the UI.

I want to understand how it does work, because it should do a RewriteMap from apache, but in Drupal installations people don't usually get access to modifying Apache.


The Apache mod rewrite module is used. /some/path is rewritten internally by Apache to index.php?q=some/path [Credit: mpdonadio].

index.php bootstraps Drupal. Drupal determines if it is able to generate a response for the path passed in the URL query q parameter - in this case /some/path. If the user has permission to access the path, the response is returned with a 200 HTTP status.

If Drupal is not able to generate a response for the path, it returns a 404 status. If it can generate a response, but the user has no permission, a 403 status is returned. Redirects send the appropriate status.

Custom modules are also able to specify status codes when returning responses.

| improve this answer | |
  • 3
    I think it would be more clear to say that /some/path is rewritten internally by apache to index.php?q=some/path, which then handles the response. A 301 or 302 would be an external rewrite. – mpdonadio Aug 16 '19 at 13:14
  • Yeah - that! Haha. I’ll edit my response. Thanks. – Jaypan Aug 16 '19 at 13:58
  • I cleaned up my whole response. – Jaypan Aug 16 '19 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.