skip to Main Content

I’ve a problem with my .htaccess file.
I recently moved the forum (IPB) that was in the root path in a subdirectory, so I wrote this .htaccess file

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/forum/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /forum/$1

RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ forum/index.php 

And this worked very well.
Basically, I wanted that old urls that were pointing to forum, were redirected to forum subdir.

But here’s the problem.
In the root path now, there is a index.php that will be the new website, I want SEO friendly urls, so I wrote this line

RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]

But this rule doesn’t work.
Every request like

www.domain.com/view/welcome/

redirect to a 404 page of the IPB forum.

I tried also to put some RewriteCond but the result is the same,
every url involving the new index.php in the root path turns in a 404 Page.

EDIT:
In /forum/
There is this .htaccess

ErrorDocument 401 /401.shtml
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forum

RewriteCond %{REQUEST_FILENAME} .*.(jpeg|jpg|gif|png)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /public/404.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L,QSA]

</IfModule>

2

Answers


  1. Chosen as BEST ANSWER

    I found the problem! I was using this:

    /* Configuration: Path to IP.Board */
    define( 'IPB_LOC', 'forum/' );
    define( 'IPS_ENFORCE_ACCESS', TRUE );//DAMN COSTANT
    
    /* Load IP.Board files */
    require_once( IPB_LOC . 'conf_global.php' );
    require_once( IPB_LOC . 'initdata.php' );
    require_once( IPB_LOC . CP_DIRECTORY. '/sources/base/ipsRegistry.php' );
    
    /* Init Registry */
    ipsRegistry::init();
    
    /* Fetch Member */
    $member = ipsRegistry::member()->fetchMemberData(); 
    $loggedIn = (bool) $member['member_id'];
    

    To check if the user was logged in the forum, but I haven't wrote this line

    define( 'IPS_ENFORCE_ACCESS', TRUE );//DAMN COSTANT
    

    That tells to IPB to NOT handle by itself the url that you are going to map (I think that this allow an external access)

    So I ended up with the .htaccess from @splash58 (thank you!)


  2. In the Rule below you match only digits after view but want welcome

    RewriteRule ^view/([0-9]+)/?$ index.php?view=$1 [NC,L]
    

    change to

    RewriteRule ^view/(.+)/?$ index.php?view=$1 [NC,L]
    

    and add some lines to void unnecessary redirects

    RewriteRule ^view/(.+)/?$ index.php?view=$1 [NC,L]
    
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/forum/
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /forum/$1
    
    RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
    RewriteCond %{REQUEST_URI} !^/index.php
    RewriteRule ^(/)?$ forum/index.php
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search