Rewrite url conflict when trying to redirect www to non www #2206

Closed
opened 2026-02-05 03:19:15 +03:00 by OVERLORD · 3 comments
Owner

Originally created by @nderambure on GitHub (Apr 21, 2021).

Using Apache 2.4.46, PHP 7.4 and MySQL 8.0.23 (via brew), if I add the rewrite rule below in my vhost to redirect www to non www, Bookstack in unable to load the file libs/tinymce/themes/modern/theme.min.js, it waits several seconds and ends up with a 0bits file.

RewriteEngine on
RewriteCond %{SERVER_NAME} !=test-bookstack.localdev [NC]
RewriteRule ^ http://test-bookstack.localdev%{REQUEST_URI} [END,QSA,R=permanent]

It then triggers the same error than in #2461.

Here is the network tab of firefox (same in chrome) :

error_redirection

It seems than the rewrite rules and conditions of the .htaccess in the public folder are conflicting with the vhost one.

How then should we config the vhost to redirect www to non www ?

Originally created by @nderambure on GitHub (Apr 21, 2021). Using Apache 2.4.46, PHP 7.4 and MySQL 8.0.23 (via brew), if I add the rewrite rule below in my vhost to redirect www to non www, Bookstack in unable to load the file `libs/tinymce/themes/modern/theme.min.js`, it waits several seconds and ends up with a 0bits file. ``` RewriteEngine on RewriteCond %{SERVER_NAME} !=test-bookstack.localdev [NC] RewriteRule ^ http://test-bookstack.localdev%{REQUEST_URI} [END,QSA,R=permanent] ``` It then triggers the same error than in #2461. Here is the network tab of firefox (same in chrome) : ![error_redirection](https://user-images.githubusercontent.com/1145642/115472100-6f5af680-a239-11eb-883a-a04dcba5d8d9.png) It seems than the rewrite rules and conditions of the .htaccess in the `public` folder are conflicting with the vhost one. How then should we config the vhost to redirect www to non www ?
Author
Owner

@ssddanbrown commented on GitHub (Apr 27, 2021):

Hi @nderambure,
Could you also post the full URL, or similar screenshot, for the tinymce.min.js request shown in your screenshot? I'd like to confirm if the URL paths are the same to understand why the two requests are behaving differently.

@ssddanbrown commented on GitHub (Apr 27, 2021): Hi @nderambure, Could you also post the full URL, or similar screenshot, for the `tinymce.min.js` request shown in your screenshot? I'd like to confirm if the URL paths are the same to understand why the two requests are behaving differently.
Author
Owner

@nderambure commented on GitHub (Apr 29, 2021):

@ssddanbrown : I've updated the rewrite rule I used in my previous post, I did a bad copy/paste (but error is the same).

I've installed the last version 21.04.3 for this test.

Here is 2 screenshots, the first for the tinymce.min.js URL and the second, for infos, the files and directory rights on disk, which seem fine, but maybe something is wrong there.

dev-console

rights

@nderambure commented on GitHub (Apr 29, 2021): @ssddanbrown : I've updated the rewrite rule I used in my previous post, I did a bad copy/paste (but error is the same). I've installed the last version 21.04.3 for this test. Here is 2 screenshots, the first for the tinymce.min.js URL and the second, for infos, the files and directory rights on disk, which seem fine, but maybe something is wrong there. ![dev-console](https://user-images.githubusercontent.com/1145642/116475214-d0a64980-a879-11eb-916d-44e7c1ab5023.png) ![rights](https://user-images.githubusercontent.com/1145642/116475244-db60de80-a879-11eb-9813-62e5f11cb67b.png)
Author
Owner

@ssddanbrown commented on GitHub (Nov 23, 2021):

Revisiting this, I'm going to close this off since it's been a while and it's an instance-specific issue.

In regards to this original statement:

It seems than the rewrite rules and conditions of the .htaccess in the public folder are conflicting with the vhost one.

In this case I'd advise disabling of .htaccess via AllowOverride Noneto prevent multiple configurations conflicting with each-other. From what I've seen it's generally good practice to avoid using .htaccess files.

@ssddanbrown commented on GitHub (Nov 23, 2021): Revisiting this, I'm going to close this off since it's been a while and it's an instance-specific issue. In regards to this original statement: > It seems than the rewrite rules and conditions of the .htaccess in the public folder are conflicting with the vhost one. In this case I'd advise disabling of `.htaccess` via `AllowOverride None`to prevent multiple configurations conflicting with each-other. From what I've seen it's generally good practice to avoid using `.htaccess` files.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#2206