1

I have custom module with page at /page wich expects $_GET['id'] to do it's job.

Here's .htaccess rewrite rule that works on empty website

RewriteRule category+/(.*)$ page.php?id=$1 [L]

On Drupal 8 I suppose that line should be

RewriteRule category+/(.*)$ page?id=$1 [L]

but it gives me 404 Error when i visit /category/5

closed as off-topic by leymannx, Jdrupal, kiamlaluno Nov 3 at 12:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on programming, PHP, SQL, etc. that do not relate directly to Drupal are off-topic here, but can be asked on Stack Overflow." – leymannx, Jdrupal, kiamlaluno
If this question can be reworded to fit the rules in the help center, please edit the question.

  • In a custom module you could simply add a route for /category/{id}. – 4k4 Nov 4 at 14:32
2

The rewrite rule will not work because page is not a valid path on the server. By default Drupal rewrites all requests into index.php. When you rewrite to page apache will expect a path page on the server.

This is not quite the right way to accomplish what you are trying to do in Drupal. However you can achieve what you are trying to do with the following

RewriteRule category+/(.*)$ page?id=$1 [R=301,L]

That will redirect category/5 to page?id=5 and you will get 5 in $_GET['id']

Check these out as well

https://www.drupal.org/docs/user_guide/en/content-paths.html

How do I retrieve the query parameters from a path?

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