mod_rewrites rules conflicting for subfolder

Nirjonadda

Well-known member
Hello,

I have issue permit the subfolder URLs then asked to cPanel support and get response this below. Please let me know that how can fix this issue?

Code:
Hello,


There were main issues in my check.


The .htaccess in public_html is conflicting. This is due to specific mod_rewrites rules. Based on the rules in place, I am confident the issue lies here in this block:


   RewriteCond %{REQUEST_FILENAME} -f [OR]

   RewriteCond %{REQUEST_FILENAME} -l [OR]

   RewriteCond %{REQUEST_FILENAME} -f [OR]

   RewriteRule ^.*$ - [NC,L]

   RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]

   RewriteRule ^.*$ index.php [NC,L]


Specifically, likely this line:


   RewriteRule ^.*$ index.php [NC,L]


It needs to be adjusted to permit the subfolder URLs like /test and /bot to load properly, otherwise the rules push the site into a 404 error. However, I tried to tweak it as a courtesy and this didn't permit the main site to function properly so I reverted it back. I would advise having a developer assist in customizing this rewrite rule in the .htaccess so you can both have a fully functional main site, plus allow the subdirectories to load for your applications.


One other thing I wanted to mention is while I could use the 'test' URL I set up with the .htaccess moved aside, bot still can't load. This appears to be an issue with the custom application in specific, as the test working indicates the implementation is funcitonal as expected.


--

Have a great day!

Joshua Browning

Technical Analyst II

cPanel, L.L.C.
 
We don't have any official support advice for this, so you would be better working towards a solution with cPanel or a server/hosting admin.

The default .htaccess doesn't by default affect sub-directories being accessible so something else must be at play.
 
@Chris D I am asked to cPanel support team and response this below. cPanel newly added support install NodeJS. So I think Xenforo .htaccess are not supported NodeJS Application?

Hello again! As my colleague Joshua indicated, it appears this issue is occurring due to the presence of this section of the default XenForo .htaccess file:

Code:
<IfModule mod_rewrite.c>

    RewriteEngine On


    #    If you are having problems with the rewrite rules, remove the "#" from the

    #    line that begins "RewriteBase" below. You will also have to change the path

    #    of the rewrite to reflect the path to your XenForo installation.

    #RewriteBase /xenforo


    #    This line may be needed to enable WebDAV editing with PHP as a CGI.

    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]


    RewriteCond %{REQUEST_FILENAME} -f [OR]

    RewriteCond %{REQUEST_FILENAME} -l [OR]

    RewriteCond %{REQUEST_FILENAME} -d

    RewriteRule ^.*$ - [NC,L]

    RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [

NC,L]

    RewriteRule ^.*$ index.php [NC,L]

</IfModule>

When I temporarily commented out the above-referenced section of the /home/nadda/public_html/.htaccess file, I was able to load the test node.js app at https://yoursite.com/test.

As indicated on this page, this section of the .htaccess file redirects unknown files or directory names to the index.php file to be used as a friendly URL: https://xenforo.com/community/threads/the-default-htaccess-file.47906/#post-514632

The index.php file is a XenForo-specific file that does not appear to know how to parse the path to the node.js applications:

Code:
09:13:02 na root@12316397 ~]cPs# more /home/nadda/public_html/index.php

<?php


$phpVersion = phpversion();

if (version_compare($phpVersion, '5.6.0', '<'))

{

    die("PHP 5.6.0 or newer is required. $phpVersion does not meet this requirement. Please

ask your host to upgrade PHP.");

}


$dir = __DIR__;

require($dir . '/src/XF.php');


XF::start($dir);


if (\XF::requestUrlMatchesApi())

{

    \XF::runApp('XF\Api\App');

}

else

{

    \XF::runApp('XF\Pub\App');

}

I would therefore recommend that you work with XenForo and/or a qualified Web developer for further assistance with this issue.

Sincerely,
Shoshana
 
Subfolders ARE allowed and aren't affected by the .htaccess file included with XenForo.

Create a folder on your server called testfolder

Create a php file called index.php in the folder with these contents
Code:
<?php

echo 'Hello World';

Navigate to your site url such as http://yoursite.com/testfolder

You should see "Hello World" on the screen. If you don't then it is a problem with your server, not the .htaccess file. OR you've edited the .htaccess file and it's your edits causing the problem.
 
We aren't able to provide support for your Node.js app. As above, the default .htaccess should not affect anything (and in my testing with PHP, HTML or other applications entirely, doesn't).
 
Subfolders ARE allowed and aren't affected by the .htaccess file included with XenForo.

Create a folder on your server called testfolder

Create a php file called index.php in the folder with these contents
Code:
<?php

echo 'Hello World';

Navigate to your site url such as http://yoursite.com/testfolder

You should see "Hello World" on the screen. If you don't then it is a problem with your server, not the .htaccess file. OR you've edited the .htaccess file and it's your edits causing the problem.

Yes this working but folder does not need in public_html directory. I have get one more response from cPanel.

202914

Getting 404 error because /test and /discord_bot folder does not have in public_html directory. So /test and /discord_bot URL are not load?

Hello,

The directories are not supposed to exist in public_html. The Node.JS Application Manager creates a custom include file which allows the /directory to load via Apache using the application specific directory instead.

However, as noted, they wouldn't load due to the custom .htaccess rules. You'd have to disable or change the rules in place.

--
Have a great day!
Joshua Browning
Technical Analyst II
cPanel, L.L.C.
 
The Node.JS Application Manager creates a custom include file which allows the /directory to load via Apache using the application specific directory instead.
That's their problem. Not XenForo's. They need to supply whatever changes are needed for XenForo and their application to live together.
 
It's happening because XenForo's .htaccess is explicitly checking if a file or directory exists, the mapping to the Node.JS application isn't going to create a directory in the web dir so it gets overwritten. Within this section you'll be able to explicitly exclude your Node application directory:

RewriteRule ^(testfolder/|data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
 
It's happening because XenForo's .htaccess is explicitly checking if a file or directory exists, the mapping to the Node.JS application isn't going to create a directory in the web dir so it gets overwritten. Within this section you'll be able to explicitly exclude your Node application directory:

RewriteRule ^(testfolder/|data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]

Does not work and Still showing The requested page could not be found.
 
Top Bottom