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

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.

  • this solved the problem but do not have enough reputation points to upvote it. Just one more question would I add RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$} to this rule or have to create another rule if a subdomain was included in this?
    – tvb
    Mar 4 '15 at 13:36
  • If you wish the same redirects to be applied to other domains / sub-domains then yes, you can just add an additional RewroteCond. Mar 4 '15 at 13:39
  • ok thank you was getting a little frustrated try to make this work.
    – tvb
    Mar 4 '15 at 13:42
  • Can be a pain if your not familiar. The important things to remember is that: 1.) The RewriteCond directives are associated with the next RewriteRule. 2.) By default the rule's are evaluated with AND (they all have to be true). 3.) They are just pattern matches against different variables the server provides. Mar 4 '15 at 13:46
  • So the additional rule for RewriteCond %{HTTP_HOST} ^subdomain\.domain\.com$ goes after RewriteRule ^(.*)$ /magento/$1
    – tvb
    Mar 4 '15 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.