Forum Moderators: phranque
I have a main domain, and an addon domain, both are for wordpress blogs.
I would like to prevent the .htaccess from the main domain from affecting the addon domain (so I could have separate rewrite rules for the addon domain).
The way cpanel seems to work is that the addon domain is in a subdirectory (addon_folder/) inside the main domain's directory (public_html/).
---------------------------------
Additionally, what is the best way of preventing addondomain.com/ from being accessible from addon_folder.maindomain.com/ and maindomain.com/addon_folder/
(I was able to create a redirect for maindomain.com/addon_folder/ to maindomain.com/, but that's about it)
--------------------
Below is what my main domain's .htaccess file looks like right now (the top part is for my wordpress permalinks; bhg = name of the addon_folder; and cpanel tells me I have Apache 1.3.37):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /index.php [L]
</IfModule>
RedirectMatch permanent ^/bhg/$ [maindomain.com...]
RewriteCond %{HTTP_HOST} !^(www\.)?addon_domain\.com
That RewriteCond will disable the (single) RewriteRule that follows it if the request is for the addon.
If you add more rules to the main domain's .htaccess file later, then you'll need to either add the above condition to each new rule, or create a 'bypass rule' at the top to skip the subsequent rules if the request is for the addon:
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
RewriteRule .* - [L]
An alternative to all of the above is to add
RewriteOptions none
RewriteOptions Inherit
I tried to write the above carefully with respect to domains, subdomains, and subdirectories so read critically.
Jim
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
RewriteRule .* - [L]
I added it to the top of the main domain's .htaccess file, and then the permalink rules nolonger applied to the addon domain. Then I created a separate .htaccess file (with it's own permalink rules) located in the addon domain's directory, and then the addon domain's permalink rules did apply to the addon domain.
(Btw, I already have wordpress plugins installed which redirect non-www to www, I'm not sure if that matters or not)
-----------------------
Now what is the best way of preventing addon_folder.maindomain.com/ and maindomain.com/addon_folder/ from being accessible.
I think I would like these URLs to generate the same type of error pages as would kujhdsfgj.maindomain.com and maindomain.com/kujhdsfgj/ where kujhdsfgj = some file that doesn't exist. Is this possible?
However, a good fix is to externally redirect those direct client requests (only!) for the addon subdirectory back to the 'proper' addon domain URL:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon_subdirectory/
RewriteRule ^addon_subdirectory/(.*)$ http://www.addon-domain.com/$1 [R=301,L]
There's a dependency here on precisely how your host accomplishes the addon-to-subdirectory mapping function. But if anything is going to work, the approach above is it. This code should be added into your main domain's .htaccess file, after the bypass code we discussed previously.
To explain the byzantine regex pattern in the RewriteCond, be aware that what we are matching in the first line is the actual request received from the browser, which will look like this:
GET /addon_subdirectory/somefile.abc HTTP/1.1
PROPFIND /addon_subdirectory/otherfile.abc HTTP/1.1
Jim
------------------
BUT, I discovered that I can create a subdomain redirect from within cpanel. So I created a redirect for addon_subdirectory.maindomain.com/ to go to www.maindomain.com/. This works perfectly. The code generated is below (it was added to the .htaccess in the addon subdirectory):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^addon_subdirectory.maindomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.addon_subdirectory.maindomain.com$
RewriteRule ^(.*)$ [maindomain.com...] [R=301,L]
-------------------
Now I just have one more problem.
For some reason, www.addon_domain.com/addon_subdirectory/ is redirecting to www.main_domain.com
I think this is due to the redirect inside the .htaccess in the main domain's directory, which is now:
RedirectMatch permanent ^/addon_subdirectory/$ [maindomain.com...]
Should this be changed to something like:
RedirectMatch permanent ^maindomain/addon_subdirectory/$ [maindomain.com...]
I'm brand new and I'm having a similiar problem.. My web hosts allows multiple domains in one hosting account, but the .htaccess folder in the root directory for the primary domain is preventing access to any of the subfolders. How can I change this?
Here is my code:
# Protect files
<Files ~ "^(.*)\.(inc¦inc\.php¦tpl¦sql)$">
Order deny,allow
Deny from all
</Files># Protect directories
<Files ~ "^(backup¦files¦images¦include¦lang¦libs(/.+)?¦temp(/.+)?¦templates(/.+)?¦javascripts(/.+)?)$">
Order deny,allow
Deny from all
</Files>
# Disable directory browsing
Options -Indexes
# Follow symbolic links in this directory
Options +FollowSymLinks
# Override PHP settings that cannot be changed at runtime
# (If your server supports PHP settings via htaccess you can comment following two lines off)
# php_value register_globals 0
# php_value session.auto_start 0
# Customized error messages
# ( If you are running in a subfolder please add it, example: "directory/index.php?httpstatus=404" )
ErrorDocument 404 index.php?httpstatus=404
# Set the default handler
DirectoryIndex index.php
# URL rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine On
## Details Link Page Rewrite##
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteRule (.*)detail/link-(.*).htm[l]?$ detail.php [QSA,NC]
## Pagination Rewrite
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteRule (.*)page-(\d+)\.htm[l]?(.*)$ $1/?p=$2 [PT,NC]
## Category redirect
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-l
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Chad
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
RewriteRule .* - [L]
I just slapped that code at the top of the root domain's .htaccess file, and inputted the appropriate domain name for addon_domain, and it prevented the rewrite rules from applying to the addon domain.
Just a disclaimer... I don't know exactly how all these codes work and I'm basically just copying and pasting as I go... your hosting account may be set up differently than mine.
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule .* - [L]
The above code would be for if example.com was the addon domain.
----------
If you scroll up, you can see Jim (jdMorgan) describe the code as follows:
"... create a 'bypass rule' at the top to skip the subsequent rules if the request is for the addon:
RewriteCond %{HTTP_HOST} ^(www\.)?addon_domain\.com
RewriteRule .* - [L]
This tells mod_rewrite to quit processing right here if the requested domain is addon_domain.com or www.addon_domain.com."