Forum

Drupal 8 - Rewrites and Redirects

Joe Schmoe
6 November 2017, 18:28
There was a post recently that was having problems with Varbase and multiple redirects.

https://www.hiawatha-webserver.org/forum/topic/2626

The problem is rooted in the Redirects module (included in the Varbase distribution) and the fact that Drupal 8 handles rewrites differently (more like WordPress). I have changed my configuration to the following and it seems to be working fine.

Old:
UrlToolkit {
....
Match /(.*)\?(.*) Rewrite /index.php?q=$1&$2
Match /(.*) Rewrite /index.php?q=$1
}


New:
UrlToolkit {
...
Match ^/(.*)\?(.*) Rewrite /index.php?$2
Match ^/(.*) Rewrite /index.php
}


There are more configurations that should change in the UrlToolkit for Drupal8. I will post soon with a more complete configuration that matches the root .htaccess file settings and incorporates .htaccess settings from other directories (like the private file path).
Hugo Leisink
6 November 2017, 22:40
Your UrlToolkit rule could probably be reduced to this:
UrlToolkit {
...
Match [^?]*(\?.*)? Rewrite /index.php$1
}
Joe Schmoe
7 November 2017, 00:55
Its black magic to me but it works! Thanks Hugo.
Hugo Leisink
7 November 2017, 20:53
[^?] means every character, except the question mark.
* means the pattern before that, 0 or more times
So, [^?]? means a string of length 0 or more, not containing a question mark.

\? means the question mark itself.
. means any character.
\?.* means a question mark, followed by 0 or more characters.
The ? at the end means that the pattern before it is optional.

So [^?]*(\?.*)? means a string not containing a question mark, optionally followed by another string starting with a question mark.
This topic has been closed.