Forum Moderators: phranque
It`s possible to see content of addon-domain.com in 3 ways:
1. Go to http://www.addon-domain.com
2. Go to http://www.addon-folder.example.com
3. Or go to http://www.example.com/addon-folder/
It is necessary that the second and third way did not work. Otherwise this content can be looked through example.com and then there`s no sense in addon-domain.com!
I have addressed in hosting support, but they have advised to move on reseller plan (instead of adjusting htaccess file)!
lol
I have tried to add following rule mod_rewrite in htaccess file of example.com:
Works, and now exmple.com/addon-folder/ redirect to example.com! And subfolders and files show all "page not found". However http://www.addon-domain.com redirect to example.com. Don ` t know why!
How correctly write a rule in .htacces?
[edited by: jdMorgan at 4:36 pm (utc) on Mar. 22, 2008]
[edit reason] de-linked [/edit]
It`s necessary to add rule in to the htaccess file of addon_folder:
RewriteEngine on
#Redirecting from addon folder to example.com if request`s from http://www.example.com на example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]#Redirecting from addon folder to example.com if request`s from http://example.com на example.com
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#Redirecting from subdomain (addon) -
http://addon_folder.example.com на example.com
RewriteCond %{HTTP_HOST} ^addon_folder.example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.addon_folder.example.com$
RewriteRule ^(.*)$ http://www.example.com [R=301,L]
Unfortunaly, there`s some nuance:
1. If request from http://example.com/addon_folder -
without "/" in the end it redirects
http://example.com//home/example/public_html/addon_folder -
404 (page not found)
2. If request to subfolder of addon_folder -
http://example.com/addon_folder/folder2 redirects
http://example.com/folder2/
But what code don`t give possibility to view addon folders content from main domain!
[edited by: jdMorgan at 4:37 pm (utc) on Mar. 22, 2008]
[edit reason] de-linked [/edit]
RewriteEngine on
#Redirect to example.com if request was made to www.addon.example.com or addon.example.com
RewriteCond %{HTTP_HOST} ^(www\.)?addon\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
In example.com/.htaccess:
# If [i]direct client request[/i] for www.example.com/addon or example.com/addon, redirect back to addon domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
RewriteRule ^addon/?(.*)$ http://addon.com/$1 [R=301,L]
You really have three choices here, and you should think about what you want to do. If you get a request for example.com/addon/ or addon.example.com, you can:
The code above shows one example for each of the first two choices in the list.
The choices you make will depend on whether or not your addon-domain folders have already been "exposed" to search engines, and how well you test your sites. Obviously, you don't want to return 403-Forbidden unless the folder paths have never been published, and you are sure that you will never link to them accidentally. All-in all, I think I prefer the rule "If an incorrect URL mentions "addon", correct it by redirecting to addon.com".
The trailing-slash problem may or may not be corrected by the modified rules above. If it is not corrected, then that means that it is a problem in the server configuration code used to rewrite addon domains to addon folders, and your host will have to fix that.
Jim
As far as I have understood it`s necessarily to write both rules - in addon folder and main?
Or, if in my case when addon folders (subdomains) requests need redirect to the main domain, I need only to add one rule in addon folder?
RewriteEngine on
#Redirect to example.com if request was made to www.addon.example.com or addon.example.com
RewriteCond %{HTTP_HOST} ^(www\.)?addon\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
However, I recommend that you either "recover" bad requests by correcting them --for example, redirecting www.addon.example.com to addon.com-- or deny the access. My feeling is that if someone bothers to type in addon.example.com, then they probably want the addon domain.
On the other hand, they should not even know about the addon.example.com address, so you might want to deny the request. Basically, either method could be called "correct" and I can only suggest how you might do it.
So, experiment, observe, learn, and decide. :)
Jim
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?addon\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
[code]2. Unfortunally second rule In example.com/.htaccess doesn`t work.
Regarding our example, i wrote next lines:
[code]
# If direct client request for www.example.com/addon or example.com/addon, redirect back to [b]example.com[/b] domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
RewriteRule ^addon/?(.*)$ http://example.com/$1 [R=301,L]
3. Also i added this rule:
#If direct client request for example.com, redirect to [b]www.example.com[/b]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
But i noticed here, what after redirect from http://example.com to http://www.example.com all links in content or menu still without www, i.e. http://example.com. :(
4. What`s give this line:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
5. If we disable access to addon_folder from main domain in htaccess file, then SE bots also can`t scan addon_folder content! Is I understand correct?
all links in content or menu still without www
Your links are defined by the code on the page, or the code that produces the page. Mod_rewrite cannot change your code, so you must change your code.
What`s give this line:RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
As described in the comments, this ensures that the "/addon/" or "/addon" was requested by the client (browser or robot) and is not the result of your internal rewrite. Without this line, the code will interact with that rewrite, leading to an "infinite" rewrite/redirect loop.
Jim
[edited by: jdMorgan at 8:47 pm (utc) on Mar. 25, 2008]
Your links are defined by the code on the page, or the code that produces the page. Mod_rewrite cannot change your code, so you must change your code.
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?$ http://www.example.com/mainsite/index.php [R=301,L]RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^index.htm$ http://www.example.com/mainsite/index.php [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^index.html$ http://www.example.com/mainsite/index.php [R=301,L]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
But in addon domain it`s not working!
RewriteCond %{HTTP_HOST} ^addon-domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.addon-domain.com/$1 [L,R=301]
2. Sorry jdMorgan! Maybe i stupid, but this code doesn`t work in htaccess file in main folder:
# If direct client request for www.example.com/addon or example.com/addon, redirect back to example.com domain
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon/?
RewriteRule ^addon/?(.*)$ http://example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^400.shtml$ http://www.example.com [R=301,L]RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^401.shtml$ http://www.example.com [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^403.shtml$ http://www.example.com [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^404.shtml$ http://www.example.com [R=301,L]
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^500.shtml$ http://www.example.com [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon_folder/?
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?addon_folder\.example\.net [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]