Seperate Domains for Subfolders + URL Cloaking

Using a single web hosting account to host multiple sites

Postby richardk » Sat Aug 04, 2007 12:41 pm

I'm a firm believer of even though it isn't broken, make sure you optimize it. So naturally, I have a question for you. Just as any programming language would use ... is there a way to make some kind of an apache/mod_rewrite version of an array so I don't have a million lines of code for all the domains I have hosted on one single account?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

# Remove the hidden directory if it shows.
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(www\.)?([^\.]+)\.[^\.]+/\2(/(.*))?$ [NC]
RewriteRule .* /%3 [R=301,L]

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.[^\.]+$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/%2/wp%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Wordpress files.
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.[^\.]+$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2/wp%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%2/wp%{REQUEST_URI} -d
RewriteRule !^([^/]+)/wp(/.*)?$ /%2/wp%{REQUEST_URI} [QSA,L]

# Other files.
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.[^\.]+$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI} -d
RewriteRule !^([^/]+)(/.*)?$ /%2%{REQUEST_URI} [QSA,L]

# Anything that doesn't exist to Wordpress.
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.[^\.]+$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^([^/]+)/wp/index\.php$ /%2/wp/index.php [L]

The "Remove the hidden directory if it shows" bit might not work.

I applied that .htaccess to the root folder of my hosting and I keep getting a 500 Internal Server Error on any page I try to access?

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

# Remove the hidden directory if it shows.
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(www\.)?th3n33ms\.net/th3n33ms(/(.*))?$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^(www\.)?kingnima\.com/kingnima(/(.*))?$ [NC]
RewriteRule .* /%3 [R=301,L]

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Wordpress files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)/wp(/.*)?$ /%3%4/wp%{REQUEST_URI} [QSA,L]

# Other files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)(/.*)?$ /%3%4%{REQUEST_URI} [QSA,L]

# Anything that doesn't exist to Wordpress.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(th3n33ms|kingnima)/wp/index\.php$ /%3%4/wp/index.php [L]

If that doesn't work, could you look in your error log (or ask your host) to find the error.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby th3n33ms » Mon Aug 06, 2007 7:10 am

I applied the .htaccess you gave me

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

# Remove the hidden directory if it shows.
RewriteCond %{HTTP_HOST}%{REQUEST_URI}
^(www\.)?th3n33ms\.net/th3n33ms(/(.*))?$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI}
^(www\.)?kingnima\.com/kingnima(/(.*))?$ [NC]
RewriteRule .* /%3 [R=301,L]

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Wordpress files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)/wp(/.*)?$ /%3%4/wp%{REQUEST_URI} [QSA,L]

# Other files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)(/.*)?$ /%3%4%{REQUEST_URI} [QSA,L]

# Anything that doesn't exist to Wordpress.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(th3n33ms|kingnima)/wp/index\.php$ /%3%4/wp/index.php [L]


And my host replied saying that they needed to make a small change to the code for security reasons, so they applied this .htaccess
Code: Select all

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteRule .* - [L]

# Remove the hidden directory if it shows.
RewriteCond %{HTTP_HOST}%{REQUEST_URI}^(www\.)?th3n33ms\.net/th3n33ms(/(.*))?$ [NC,OR]
RewriteCond %{HTTP_HOST}%{REQUEST_URI}^(www\.)?kingnima\.com/kingnima(/(.*))?$ [NC]
RewriteRule .* /%3 [R=301,L]

# Add missing trailing slashes.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI}/ -d [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Wordpress files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4/wp%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)/wp(/.*)?$ /%3%4/wp%{REQUEST_URI} [QSA,L]

# Other files.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/%3%4%{REQUEST_URI} -d
RewriteRule !^(th3n33ms|kingnima)(/.*)?$ /%3%4%{REQUEST_URI} [QSA,L]

# Anything that doesn't exist to Wordpress.
RewriteCond %{HTTP_HOST} ^(www\.)?((th3n33ms)\.net|(kingnima)\.com)$ [NC]
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule !^(th3n33ms|kingnima)/wp/index\.php$ /%3%4/wp/index.php [L]


I have no idea what they changed but I do know that everything is working perfectly now! Thanks a lot richardk couldn't have gotten anything (at all) done without your help!
th3n33ms
 
Posts: 6
Joined: Sun Jun 03, 2007 3:33 pm

Previous

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 1 guest

cron