Magento 1.9 – Fixing 404 Errors in Subdirectories

magento-1.9urlurl-rewrite

I have magento located in a subdirectory in public_html/magento the .htaccess I used to redirect magento to the root is based on installing Magento in subdirectory


Root .htaccess file contains

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteCond %{REQUEST_URI} !^/magento/
RewriteRule ^(.*)$ /magento/$1

The .htaccess in magento only has the change of

you can put here your magento root folder
path relative to web root

RewriteBase /

I would like to be to be able to access other web applications which are located in public_html ie (blog, CMS, forum) without magento throwing a 404 error.

I tried using Serve main domain from subdirectory with .htaccess example but magento still takes over.

RewriteEngine on
# Part 1
RewriteCond %{HTTP_HOST} ^(www.)?topdomain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/topdomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /topdomain/$1
# Part 2
RewriteCond %{HTTP_HOST} ^(www.)?topdomain.com$ [NC]
RewriteRule ^(/)?$ topdomain/index.php [L]

what do I need to put in the root .htaccess to make magento play nicely so
that I can have

└── httpd
    ├── blog (topdomain/blog
    ├── cart (topdomain
    ├── forum (topdomain/forum

Best Answer

Assuming the objective is to have the raw domain link to Magento, but allow other folders in the root domain to work, you can just add a further RewriteCond for each top level directory you wish to work.

root .htacces

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteCond %{REQUEST_URI} !^/magento/
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_URI} !^/forums/
RewriteRule ^(.*)$ /magento/$1

The RewriteCond's are basically saying if the URL doesn't start with /magento/ and doesn't start with /blog/ and doesn't start with /forums/ then redirect to Magento.

Related Topic