How do I change my server root directory (.htaccess)

HustlinHard

(M)ad Man
Oct 31, 2007
313
5
18
Vancouver
So basically what I'm trying to do is modify my .htaccess so that my main site's base folder is in a subfolder of public_html just like my addon domains.

Something like this:

public_html/mainsubfolder
public_html/addon1
public_html/addon2

Now this would be very simple if I just wanted to do a redirect, but I don't want the URL of the browser to show a subfolder.

I want to see:
MainDomain Name Registration
NOT http://www.maindomain.com/mainsubfolder

The other dilemma I have is that I don't want it to negatively affect SEO by having Google index two versions of the site (maindomain.com & maindomain.com/subfolder) or some other factors.

The reason I want to do this is for organization mainly, since I don't want to have all my website/wordpress/other script files and folders in the public_html folder directly, it makes it hard to manage things this way.


So far what I've found is the following .htaccess code:

# Turn on rewrites.
RewriteEngine on

# Only apply to URLs on this domain
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$

# Only apply to URLs that aren't already under folder.
RewriteCond %{REQUEST_URI} !^/mainsubfolder/

# Don't apply to URLs that go to existing files or folders.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all those to insert /folder.
RewriteRule ^(.*)$ /mainsubfolder/$1

# Also redirect the root folder.
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteRule ^(/)?$ mainsubfolder/index.php [L]

Which should do what I want, but I'm concerned about the SEO consequences. I figure with all the brains we got here, hopefully someone can help me solve this conundrum.
 


Code:
RewriteEngine on
RewriteBase /

# force www.
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Canonical index.(php|html)
RewriteCond %{THE_REQUEST} "/index\.(php|html) HTTP" [NC]
RewriteRule ^(.*/)?index\.(php|html)$ http://www.example.com/$1 [R=301,NS,NC,QSA,L]

# move base directory
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) /example.com/$1 [L]

This should work, C&P from working site that does what you want to do, just change site name.

Move all files and folders (Not addon domain folders) to the new directory.

As far as SEO, the search engines won't notice, the URLs will stay the same.
 
Thanks for the responses guys! I've been currently using the first configuration I posted in my OP, but I think it may have been causing some problems. I've noticed some things being redirected wrong, and when I edited certain plugins in WP, it would log me out and redirect me to the login page, but when I tried to login it wouldn't give me access.

A few issues like that which I haven't encountered before..

Well, you should just edit the apache config. If you have access to that.

I wasn't able to find this in the WHM

This is your best option, look up 'apache virtual host'.

Wasn't able to find it in WHM

Code:
RewriteEngine on
RewriteBase /

# force www.
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Canonical index.(php|html)
RewriteCond %{THE_REQUEST} "/index\.(php|html) HTTP" [NC]
RewriteRule ^(.*/)?index\.(php|html)$ http://www.example.com/$1 [R=301,NS,NC,QSA,L]

# move base directory
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) /example.com/$1 [L]
This should work, C&P from working site that does what you want to do, just change site name.

Move all files and folders (Not addon domain folders) to the new directory.

As far as SEO, the search engines won't notice, the URLs will stay the same.

This sounds promising but, excuse my .htaccess newbiness, what exactly would I have to replace here? Would I just change every instance of "example.com" to "mydomain.com"? Wouldn't I have to include the subfolder that is being used for the site somewhere in there? My guess is that the last line:

RewriteRule (.*) /example.com/$1 [L]

would have to be replaced with the folder, or am I completely off?
 
This sounds promising but, excuse my .htaccess newbiness, what exactly would I have to replace here? Would I just change every instance of "example.com" to "mydomain.com"?

Yes

Wouldn't I have to include the subfolder that is being used for the site somewhere in there? My guess is that the last line:

RewriteRule (.*) /example.com/$1 [L]

would have to be replaced with the folder, or am I completely off?

Yes, change that to the new subfolder name

Your addon domains are (probably) in subdirectories such as /addondomain1.com/ so you can just make a subdirectory /maindomain.com/ and put the account's files in there. You can name it whatever you want.

Don't put your wordpress .htaccess directives in this file, put those in the .htaccess file in the new subdirectory.

The only thing that should be in the .htaccess of the main public_html directory is the code I gave you above.

Then, in the new subdirectory, you'd have your main .htaccess file.

In /home/account/public_html/.htaccess

Code:
RewriteEngine on
RewriteBase /

# force www.
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Canonical index.(php|html)
RewriteCond %{THE_REQUEST} "/index\.(php|html) HTTP" [NC]
RewriteRule ^(.*/)?index\.(php|html)$ http://www.example.com/$1 [R=301,NS,NC,QSA,L]

# move base directory
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) /example.com/$1 [L]

In /home/account/public_html/maindomain.com/.htaccess

Code:
IndexIgnore *
Options -Indexes +FollowSymLinks
DirectoryIndex index.php index.html

<Files php.ini> 
	order allow,deny 
	deny from all 
</Files>
<Files wp-config.php> 
	order allow,deny 
	deny from all 
</Files>

########## etc, etc - whatever you have in .htaccess now

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# END WordPress