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.