PHPbb URL redirection with WP

xray
User ww
User ww
Posts: 34
Joined: Mon Dec 24, 2018 9:48 pm

PHPbb URL redirection with WP

Post by xray »

I am working with PHPbb and Wordpress using your plugin. I have it set up, but like your site the forums can be accessed outside of wordpress even if it setup with the wrapper. I realize that I need to create htaccess rules so that if someone types, mysite.com/forums (direct) path to forum that instead it will direct them to mysite.com/forum (which would be the path to the wrapper inside wordpress. This way wordpress and the forums are actually integrated.
I had used Joomla in the past and recently switched to wordpress. I am not sure how WP handles these or if it can do it without breaking all the forum links. The goal is to make sure that WP and PHPbb work together.

bb is the forum name. What I am not getting is wordpress does not create a html when linking to the frame. So I am not sure of the file name for the 301 redirect. I almost think it would be mysite.com/bb/ - but I think it needs a file to land.

The following code is used from a previous sample I used on Joomla. I think the app.php within this code is some sort of controller that makes the connection between this htaccess file added to the forums and then another htaccess file added to the root of WP.

Here is a sample htaccess file for the forums: <CODE><s>

Code: Select all

</s><IfModule mod_rewrite.c>
RewriteEngine on

# code bb is the forum name
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} /bb(\/?)$
RewriteRule (.*) /forums.html [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/index.php
RewriteRule (.*) /forums.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/ucp.php
RewriteRule (.*) /forums/user.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/viewforum.php
RewriteRule (.*) /forums/forum.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/viewtopic.php
RewriteRule (.*) /forums/topic.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/memberlist.php
RewriteRule (.*) /forums/members.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/report.php
RewriteRule (.*) /forums/report.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/posting.php
RewriteRule (.*) /forums/post.html?%{QUERY_STRING} [R=301,L]
RewriteCond %{REQUEST_FILENAME} /bb/mcp.php
RewriteRule (.*) /forums/moderator.html?%{QUERY_STRING} [R=301,L]
# end of p8pbb bridge code

#
# Uncomment the statement below if URL rewriting doesn't
# work properly. If you installed phpBB in a subdirectory
# of your site, properly set the argument for the statement.
# e.g.: if your domain is test.com and you installed phpBB
# in http://www.test.com/phpBB/index.php you have to set
# the statement RewriteBase /phpBB/
#
#RewriteBase /

#
# Uncomment the statement below if you want to make use of
# HTTP authentication and it does not already work.
# This could be required if you are for example using PHP via Apache CGI.
#
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

#
# The following 3 lines will rewrite URLs passed through the front controller
# to not require app.php in the actual URL. In other words, a controller is
# by default accessed at /app.php/my/controller, but can also be accessed at
# /my/controller
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ app.php [QSA,L]

#
# If symbolic links are not already being followed,
# uncomment the line below.
# http://anothersysadmin.wordpress.com/2008/06/10/mod_rewrite-forbidden-403-with-apache-228/
#
#Options +FollowSymLinks
</IfModule>

# With Apache 2.4 the "Order, Deny" syntax has been deprecated and moved from
# module mod_authz_host to a new module called mod_access_compat (which may be
# disabled) and a new "Require" syntax has been introduced to mod_authz_host.
# We could just conditionally provide both versions, but unfortunately Apache
# does not explicitly tell us its version if the module mod_version is not
# available. In this case, we check for the availability of module
# mod_authz_core (which should be on 2.4 or higher only) as a best guess.
<IfModule mod_version.c>
	<IfVersion < 2.4>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfVersion>
	<IfVersion >= 2.4>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfVersion>
</IfModule>
<IfModule !mod_version.c>
	<IfModule !mod_authz_core.c>
		<Files "config.php">
			Order Allow,Deny
			Deny from All
		</Files>
		<Files "common.php">
			Order Allow,Deny
			Deny from All
		</Files>
	</IfModule>
	<IfModule mod_authz_core.c>
		<Files "config.php">
			Require all denied
		</Files>
		<Files "common.php">
			Require all denied
		</Files>
	</IfModule>
</IfModule><e>
</e></CODE>

Hopefully this makes sense and thanks for checking
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: PHPbb URL redirection with WP

Post by axew3 »

What I am not getting is wordpress does not create a html when linking to the frame. So I am not sure of the file name for the 301 redirect. I almost think it would be mysite.com/bb/ - but I think it needs a file to land.
the above isn't clear to me as you explained, but resuming, that's all what you want achieve:
in iframe mode: you want that any user that try to access phpBB pointing to the direct Url, redirected to WP page with iframed phpBB.

Which code are you using?
on v1 and v2 code, to achieve this, you need to use the htaccess trick to redirect users to correct iframe page: this solution (that's the more safe because there is no way to surpass the htaccess redirect and user will be forced to the url you want redirect him, even with javascript disabled on browser (which by the way is not common options on users browser)) by the way it require to edit the phpBB htaccess file, the phpBB notification file and a check against passed urls switching to the correct one on wordpress created page-forum.php, to pass the correct real phpBB url to, load phpBB iframe into the wp page.
This is still done for urls/links generated by plugin's widgets last posts, which if you click on (and you setup as yes the very last option on plugin admin page, the one related to widgets links that need to point to iframed wp page or full phpBB url as needed) are still processed by the code on top of the page-forum.php (or whatever you name it).
All the joomla htaccess code above, isn't useful here, nor anything else but some custom htaccess code that do the right redirect. The problem with this solution, is complicated by the fact that the var p that is also a default var in phpBB, need to be also rewrite/renamed and treat as separated making compatible this aspect and avoid the conflict between wp and the passed phpBB url. The concept of this is quite hard, but you can maybe understand the joke following to read the v2 code procedure, about htaccess (see on bottom of the page) and looking to the page-forum.php code on top.
Or follow with questions and i will be glad to be more precise about the logic of this.

So to simplify life for all, without using htaccess, there is the new v3 code, and base64 encoded urls.
It differ from v1 and v2 because it is pure javascript solution, and you do not need to edit nothing but just add the code on overall_footer.html and overall_header.html of the phpBB template.
On v3 code, any phpBB url accessed directly, will rewrite the request pointing to the WP page:
follow the v3 integration code, read all steps until the bottom of the page
https://www.axew3.com/w3/2018/12/phpbb- ... iframe-v3/

You really want use htaccess solution?

p.s NOTE that to use the v3 code you need to download the new page-forum.php and manually replace the one you built on plugin admin page, and that so you find inside your active WP template folder-
xray
User ww
User ww
Posts: 34
Joined: Mon Dec 24, 2018 9:48 pm

Re: PHPbb URL redirection with WP

Post by xray »

You've been busy...Awesome, I will look at v3 a little more, I think this is what I am looking to do. Are you going to try it with your site/forum or have a demo maybe for show.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: PHPbb URL redirection with WP

Post by axew3 »

Actually on this online example it is applied the v2 version, i will apply the v3 as soon, thinking to do yesterday, no time at all, so postponed maybe to today my night time: it has been tested working fine on several tests now.

What substantially change on v3 is the overall_header.html piece of code, that redirect all direct phpBB requests to the iframed wp page.
It just look if the page is a frame, if not, reload pointing to the wp iframed page:
Since it is pure js, browsers may be affected by this, but what the advantage here about seo, is that spiders simply will ignore and will follow indexing the forum with real urls.
What nice, that after any user that try to access these links (direct and real phpBB urls), are redirected to iframed wp page with encoded base64, as long as they have javascript enabled on browser.
This is a perfect solution/concept for a correct iframe integration.
If js disabled on browser, then the user can still access the forum via direct url.

Yes you could force under any aspect this with htaccess leaving no chance to the user to "live his life as he want",
but this last v3 concept, is a more complete solution, if no other particular requirement need to be satisfied.

I think to finalize, there is another aspect i would like to fix.
On actual code, when you right click to copy the link for example or to open link on new tab, it pass the encoded link that point to iframe.
I realize that it's better to remove this behavior, because on v3 there is already the overall_header.html code that execute the redirection.
Better pass real urls, there is no need to pass modified links. So it is possible to paste everywhere with easy the real phpBB url.

I will do this fix asap and i will apply v3 code here online with upgrade of the board to latest release.

p.s if subscribed you'll get the notification link with var iframe appended because at date of this reply, this is v2 code that work in this way and require to edit phpBB notification email temeplate files.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: PHPbb URL redirection with WP

Post by axew3 »

p.s: just looking on fly, yes this overall_footer.html piece of code:

Code: Select all

$( "a" ).contextmenu(function() {
 var ohref = $(this).attr("href");
 var href = this.href; // treath like an external because only open New tab or New window
  d = w3allNormalize_phpBBUrl(href);
  hrefEnc = window.btoa(unescape(encodeURIComponent(d)));
  href1 = wordpress_url_page_forum + '/?w3=' + hrefEnc;  
    
  $(this).attr("href", href1); // send out encoded
  $(this).mouseleave(function() { // reset (replaced 'mouseup')
  $(this).attr("href", ohref);
  });
});
IF the code on overall_header.html has been applied, then this code should be removed or changed into

Code: Select all

$( "a" ).contextmenu(function() {
 var ohref = $(this).attr("href");
 var href = this.href; // treath like an external because only open New tab or New window
 $(this).attr("href", this.href);
  $(this).mouseleave(function() { // reset (replaced 'mouseup')
  $(this).attr("href", ohref);
  });
});
That lead to equal result: and it should be perfect now.
User avatar
axew3
w3all User
w3all User
Posts: 2883
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

Re: PHPbb URL redirection with WP

Post by axew3 »

so minutes ago, and in 10 min (excluded upload time!) the board has been updated to latest 3.2.5 and the iframe code has been updated to latest v3.
Still not checked all, but should work smooth and fine. If all ok, the code will be so added as official release.
The part of code on overall_header.html has been updated due to a wrong js instruction (that was working fine, but not correct).
Post Reply