Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 5
htaccess for magento in subdirectory
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 

Hi everyone,

I’m having trouble with Magento installed into a subdirectory ("magento"), which I want transparently rewritten so that the subdirectory isn’t part of the URL. First, my .htaccess:

Options +FollowSymlinks
RewriteEngine on

RewriteRule 
^$ /magento/index.php [L,QSA]

RewriteCond 
%{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteCond 
%{REQUEST_FILENAME} !-l
RewriteRule 
^(.*)$ /magento/$1 [L,QSA]

As you can see, the first rule rewrites an empty request to the index, and the second rule should rewrite everything to include the subdirectory. The backend web configuration has store URLs set correspondingly i.e. http://domain/ rather than http://domain/magento.

With this configuration, the frontend works perfectly, with everything rewritten nicely so as not to include “/magento/”. But in the backend, all links are of the form “/index.php/” which doesn’t work - using the dashboard as an example, it should be “/admin/dashboard” (works) but instead you are redirected to “/index.php/admin/dashboard” (doesn’t work).

Does anyone have a rewrite like the above working to effectively make the document root transparently rewrite into the magento subdirectory for both the frontend and backend?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Crucial
Enthusiast
 
Avatar
Total Posts:  770
Joined:  2007-11-07
Phoenix, AZ
 

Wouldn’t it be easier to just move Magento to the root directory? I mean, I’m sure you’ve thought of that, just wondering what your reasoning is for not doing it. Seems like a lot of work hmmm

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 

Reason for doing so is fairly simple - often you will have a domain that is primarily used for Magento, but want to host something else (blog, CMS, forum etc) on the same account/domain. This way you can keep magento and any other apps in separate directories below your document root, with the other apps accessible from /appname but with magento as the “default” application.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 

Someone else with what sounds like the same problem. Is it really possible that no-one else is running Magento in a subdirectory and rewriting to remove it from the URL?

 
Magento Community Magento Community
Magento Community
Magento Community
 
netstralogy
Jr. Member
 
Total Posts:  29
Joined:  2008-04-09
 

I did install magento on a sub-domain.  It was working fine until it was time for me to install my SSL.  Turned out in order to install SSL, the domain has to be in it’s own domain.  Now I have to move magento to the main directory. 

If you’re planning on using SSL, my suggestion would be to just move your site to a sub-directory in the main domain.  Saves you a lot of trouble.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Crucial
Enthusiast
 
Avatar
Total Posts:  770
Joined:  2007-11-07
Phoenix, AZ
 
Netstralogy - 23 June 2008 11:39 AM

I did install magento on a sub-domain.  It was working fine until it was time for me to install my SSL.  Turned out in order to install SSL, the domain has to be in it’s own domain.  Now I have to move magento to the main directory.

I’m a little confused by this. If you purchase a domain-only validation certificate (which is what most people buy), you can only purchase it for one domain (e.g. http://www.domain.com, domain.com, secure.domain.com). So if you had your site running on a subdomain, you would have to purchase the SSL cert for the subdomain. HTTPS wouldn’t work on anything else unless you bought a cert for each or bought a wildcard certificate, so it would work on *.domain.com.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 

Please let’s keep this thread on-track, my question is nothing to do with subdomains, they will work in exactly the same way. The question is about rewriting to remove a Magento subdirectory. It doesn’t matter whether the parent is the top level of a domain, subdomain or another directory.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lorenzo66
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-06-04
London, UK
 

Haz,
your request makes perfectly sense. In fact I have the same kind of problem.
Unfortunately I don’t have the option to point my main domain on a subfolder and I want to keep the main folder clean.
I tried to use your .htacces configuration BEFORE installing magento and I have the error: Input file not specified or something along the line.
Using .htaccess after installing in the usual way, it works for the first page (home) but then all goes back to the /magento/ folder.
Maybe this might help some “expert” to find out the issue.
BTW, do you use the .htacces before or after the installation?
The version I am using is the 1.0.19870.4

Lorenzo

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unirgy
Guru
 
Avatar
Total Posts:  478
Joined:  2007-09-07
 

ah, i know smile

in configuration > web > base url - when in Default configuration set normal http://domain/magento/ url - this will affect all areas including admin
then switch to your website or store and set http://domain/ - this will affect your store frontend

i’m curious if it worked for you smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lorenzo66
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-06-04
London, UK
 

Saharian,
thank you for your suggestion, but it did’t work. And I couldn’t manage to go back either. Lucky enough that was just a test site.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unirgy
Guru
 
Avatar
Total Posts:  478
Joined:  2007-09-07
 

so default base URL is http://domain/magento/ and store specific base URL is http://domain/ and it doesn’t work?

what error does it give?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Crucial
Enthusiast
 
Avatar
Total Posts:  770
Joined:  2007-11-07
Phoenix, AZ
 
Saharian - 24 June 2008 06:21 PM

so default base URL is http://domain/magento/ and store specific base URL is http://domain/ and it doesn’t work?

what error does it give?

No, he has Magento installed in domain.com/subdir, and wants to access it via domain.com (no subdir). It’ll require some complex mod_rewrite rules, and seems much easier to just install it in the root directory. The organizational reason doesn’t make sense either. Install Magento in the root directory, as it’s your main application, and install everything else in sub-dirs (blog, forum, etc.).

 
Magento Community Magento Community
Magento Community
Magento Community
 
SimpleHelixcom
Enthusiast
 
Avatar
Total Posts:  906
Joined:  2007-08-31
Huntsville, AL
 

Well, some of our clients also requested this type of feature and this seems to work pretty well for us:

In your root folder, just create an .htaccess with the following:

DirectoryIndex magento/index.php

where magento is your sub-folder

It’s a pretty simple and straightforward. It should do what you need to do.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 
Crucial - 26 June 2008 12:02 AM

The organizational reason doesn’t make sense either. Install Magento in the root directory, as it’s your main application, and install everything else in sub-dirs (blog, forum, etc.).

That is a bad idea. As you stick more and more unrelated directories and files in the top-level Magento directory you will lose track of what is part of the Magento application and what is not, making it difficult to manage/upgrade/backup/restore your Magento source tree. It’s really not that complicated, and is standard practice for other apps e.g. Drupal includes example rewrites in its default .htaccess.

Specifying a different DirectoryIndex alone only effectively rewrites the bare domain, every internal link will still reference the subdirectory.

Still looking for a complete solution…

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lorenzo66
Jr. Member
 
Avatar
Total Posts:  16
Joined:  2008-06-04
London, UK
 

Hello,
I need a solution for this problem too (sure should be plenty of people out there facing the same issue) but, as I fully support haz point, I don’t have a lot of experience with apache, and not even with magento.
My only guess is that magento might “confuse” url (as the client sees it) and physical location where the files are.
I hope that some expert on both magento and apache could come up with some solution or at least some idea where to look for the solution.
Haz, let’s keep pushing!

Lorenzo

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lloyd Hazlett
Jr. Member
 
Avatar
Total Posts:  24
Joined:  2008-06-05
Melbourne, Australia
 

I had hoped that the newly added support for a custom admin URL in 1.1.1 might have meant that this would start working, but still no luck. Has anyone else found a solution yet?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 5