How to run a Joomla website in a sub-directory where Wordpress is installed in web root
Asked Answered
S

3

9

I have Wordpress installed at example.com.

I did have Joomla 3 installed at example.com/joomla.

Now example.com/joomla loads a Wordpress 404 for some reason.

Even example.com/joomla/index.php loads a Wordpress 404.

I can see the Joomla files are intact in the /joomla folder, and configuration.php contains the correct db details. I can see in phpMyAdmin the db is intact.

When I checked .htaccess in the /joomla folder it was called htaccess.txt. Renaming this to .htaccess did not resolve the problem.

How can I ensure the Joomla 3 website runs properly again from a sub-directory where Wordpress is installed in the root domain?

Thanks in advance.

Update: this is the .htaccess in the web root. The /joomla-folder has a default Joomla .htaccess

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/?wp\-content/+debug\.log$
        RewriteRule .* - [F,L,NC]
</IfModule>
<IfModule !mod_rewrite.c>
    <Files "debug.log">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order deny,allow
        Deny from all
    </IfModule>
    </Files>
</IfModule>

# BEGIN litespeed noabort
<IfModule rewrite_module>
        RewriteEngine On
        RewriteRule .* - [E=noabort:1]
</IfModule>
# END litespeed noabort

# Redirect HTTP to HTTPS
<IfModule rewrite_module>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>

# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/bmp application/java application/msword application/vnd.ms-fontobject application/x-msdownload image/x-icon image/webp application/json application/vnd.ms-access application/vnd.ms-project application/x-font-otf application/vnd.ms-opentype application/vnd.oasis.opendocument.database application/vnd.oasis.opendocument.chart application/vnd.oasis.opendocument.formula application/vnd.oasis.opendocument.graphics application/vnd.oasis.opendocument.presentation application/vnd.oasis.opendocument.spreadsheet application/vnd.oasis.opendocument.text audio/ogg application/pdf application/vnd.ms-powerpoint image/svg+xml application/x-shockwave-flash image/tiff application/x-font-ttf application/vnd.ms-opentype audio/wav application/vnd.ms-write application/font-woff application/font-woff2 application/vnd.ms-excel
    <IfModule mod_mime.c>
        # DEFLATE by extension
        AddOutputFilter DEFLATE js css htm html xml
    </IfModule>
</IfModule>
<FilesMatch "\.(html|htm|rtf|rtx|svg|txt|xsd|xsl|xml|HTML|HTM|RTF|RTX|SVG|TXT|XSD|XSL|XML)$">
    <IfModule mod_headers.c>
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</FilesMatch>
<FilesMatch "\.(bmp|class|doc|docx|eot|exe|ico|webp|json|mdb|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|pot|pps|ppt|pptx|svg|svgz|swf|tif|tiff|ttf|ttc|_ttf|wav|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|BMP|CLASS|DOC|DOCX|EOT|EXE|ICO|WEBP|JSON|MDB|MPP|OTF|_OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|POT|PPS|PPT|PPTX|SVG|SVGZ|SWF|TIF|TIFF|TTF|TTC|_TTF|WAV|WRI|WOFF|WOFF2|XLA|XLS|XLSX|XLT|XLW)$">
    <IfModule mod_headers.c>
         Header unset Last-Modified
    </IfModule>
</FilesMatch>
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*\/)?w3tc_rewrite_test([0-9]+)/?$ $1?w3tc_rewrite_test=1 [L]
    RewriteCond %{HTTP:Accept-Encoding} gzip
    RewriteRule .* - [E=W3TC_ENC:_gzip]
    RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
    RewriteRule .* - [E=W3TC_PREVIEW:_preview]
    RewriteCond %{REQUEST_METHOD} !=POST
    RewriteCond %{QUERY_STRING} =""
    RewriteCond %{REQUEST_URI} \/$
    RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
    RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
    RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core

# BEGIN WordPress
<IfModule rewrite_module>
RewriteEngine On
RewriteRule ^(dynamic-keyword-plugin-joomla)($|/) - [L]
RewriteBase /
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

# Wordfence WAF
<IfModule LiteSpeed>
php_value auto_prepend_file '/home/doigwebsite/public_html/wordfence-waf.php'
</IfModule>
<Files ".user.ini">
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
</IfModule>
</Files>

# END Wordfence WAF


# BEGIN MainWP

# END MainWP

#<IfModule mod_fcgid.c>
#MaxRequestLen 31457280
#</IfModule>

FileETag None
Header unset ETag 
Header unset Pragma

<IfModule mod_security.c>
  SecFilterEngine Off
  SecFilterScanPOST Off
</IfModule>

Update2: Joomla is now working. I believe it might be caused by my own confusion around hosting arrangements - there was a transfer of host recently.

Apologies.

Suspiration answered 19/7, 2017 at 18:24 Comment(0)
T
6

Add the following to the .htaccess file in the root of your WordPress install, immediately after the line with RewriteEngine On:

RewriteRule ^(joomla)($|/) - [L]

For instance:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
...

Becomes

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(joomla)($|/) - [L]
...

This prevents WordPress from loading only when the requested path begins with /joomla/.

Trinity answered 22/7, 2017 at 17:1 Comment(5)
Thanks Xander. My Joomla directory contains a hypen, e.g: /joomla-directory. I tried the code in .htaccess above (replacing joomla with joomla-directory) but the issue remains.Suspiration
Can you update your question with your current .htaccess?Trinity
Sure. Added to the end of my question. Thanks.Suspiration
Hi Xander. The problem is resolved now. I think I made a mistake with the hosting - I recently toggled between hosts, and perhaps Joomla was not installed on the test host for some unknown reason.Suspiration
Glad you got it sorted 👍Trinity
S
1

If you have installed the nginx on your server, you can use the following code and add it to your server block just before closing of server block.

location = / {
    try_files $uri $uri/joomla-directory /joomla-directory/index.php?$args;
}

location /joomla-directory {
    index index.php;
    try_files $uri $uri/ /joomla-directory/index.php?$args;
}

Hope this will help.

If you are on shared hosting, please paste your htaccess in your WordPress root installation, and also the directory structure.

Showthrough answered 24/7, 2017 at 18:7 Comment(1)
Hi Nitin. I am using Litespeed shared hosting.Suspiration
V
1
<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteRule ^(joomla)($|/) - [L]
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.php [L] 
</IfModule> # END WordPress
Voluptuary answered 27/7, 2017 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.