An error what redirecting to the non-www version

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
User avatar
halil16
Registered User
Posts: 1463
Joined: Fri Jul 24, 2020 11:30 pm
Location: Turkiye
Name: Halil

An error what redirecting to the non-www version

Post by halil16 »

Hello,
I tried several .htaccess codes to redirect the site to a non-www url. But it redirects to the main site every time.

So when I enter www.domain.com/forums/, it redirects to domain.com, not domain.com/forums/.

WordPress is installed in the main folder. When www is entered on any page there, the rest of the url goes to the relevant page without changing. But I couldn't do this in phpBB. Force server URL settings in ACP don't work in this regard.

its .htaccess

Code: Select all

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /forums/

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

....
I feel like I'm missing something, but I can't find it.
Last edited by thecoalman on Sat Jan 11, 2025 7:37 pm, edited 1 time in total.
Reason: Moved to Custom Coding
User avatar
halil16
Registered User
Posts: 1463
Joined: Fri Jul 24, 2020 11:30 pm
Location: Turkiye
Name: Halil

Re: An error what redirecting to the non-www version

Post by halil16 »

When I tried this code, it worked. It worked instantly in the incognito tab, but it took a while for the normal one.

Code: Select all

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/forums/$1 [R=301,L]
Buy me a coffee ☕
Hire me for your phpBB board. 🚩
Introducing Mobile Upgrade! *Make your phpBB board like an app! 📱
O BeldeThatTowns*for sale*(Now$790) 🏷️
"The day we'll need ideas more than possessions, we'll find the secret to true wealth." - Peyami Safa /peˈjɑːmi saˈfɑː/
User avatar
thecoalman
Community Team Member
Community Team Member
Posts: 6518
Joined: Wed Dec 22, 2004 3:52 am
Location: Pennsylvania, U.S.A.

Re: An error what redirecting to the non-www version

Post by thecoalman »

Something to be aware of with 301 redirects, the browser will cache them.
“Results! Why, man, I have gotten a lot of results! I have found several thousand things that won’t work.”

Attributed - Thomas Edison
User avatar
halil16
Registered User
Posts: 1463
Joined: Fri Jul 24, 2020 11:30 pm
Location: Turkiye
Name: Halil

Re: An error what redirecting to the non-www version

Post by halil16 »

I get it, thank you.
Buy me a coffee ☕
Hire me for your phpBB board. 🚩
Introducing Mobile Upgrade! *Make your phpBB board like an app! 📱
O BeldeThatTowns*for sale*(Now$790) 🏷️
"The day we'll need ideas more than possessions, we'll find the secret to true wealth." - Peyami Safa /peˈjɑːmi saˈfɑː/

Return to “phpBB Custom Coding”