homepage Welcome to WebmasterWorld Guest from 54.166.100.8
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Addon domains! Is there any sense on it on Apache?
Addon folders are in a folder of the main domain and can be accessible...
galench




msg:3607142
 9:21 am on Mar 21, 2008 (gmt 0)

The basic domain - example.com
Addon domain - addon-domain.com
Folder of addon-domain.com - addon-folder

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]

 

galench




msg:3607211
 12:57 pm on Mar 21, 2008 (gmt 0)

Well i found some decision.

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]

jdMorgan




msg:3607330
 3:14 pm on Mar 21, 2008 (gmt 0)

In /addon_folder/.htaccess:

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]

Checking THE_REQUEST ensures that /addon was directly requested by the client, and is not the result of the internal rewrite used to map addon.example.com to /addon. If the request was direct, we want to redirect it. If the request was the result of the internal rewrite, we do not want to redirect it, because that would break the addon subdomain.

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:

  • Redirect to addon.com
  • Redirect to example.com
  • Deny access -- Return 403-Forbidden

    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

  • galench




    msg:3607941
     11:46 am on Mar 22, 2008 (gmt 0)

    I glad to hear you here Jim!
    So, it is not necessary for me redirect example.com/addon/ or addon.example.com or www.addon.example.com to addon.com! I want for it looks like what addon domains content do not exist on the main domain!
    No links to this content from the basic domain exist since there aren`t present any content now. Accordingly it aren`t presented in search engines. Therefore I think what it isn`t necessary 403 or 404 Page to be load if request addon folders (subfolders, files). It`s necessary redirect to main domain.

    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]

    jdMorgan




    msg:3608018
     2:58 pm on Mar 22, 2008 (gmt 0)

    Because the answers depend on what *you* want to do, and why you want to do it, all I can recommend is that you experiment with these ideas until you find the method you like.

    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

    galench




    msg:3608202
     9:28 pm on Mar 22, 2008 (gmt 0)

    Sorry Jim, but i tried edit both files - and unsuccessfully. Works nothing! I do not know why, but I will try some more time, but not today!
    Also I wish to specify, whether it is necessary to do redirect from http:// to [www...]
    Is it gives any advantages?

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

    2. Can you explain please for what is THE_REQUEST necessary? I can not understand that it gives!? It like copies the inquiry address entirely, and then?
    3. Also, as I understand, search engines bots cannot get access to addon folder too! Isn`t it? Because it`s not need to me...

    galench




    msg:3610420
     8:14 pm on Mar 25, 2008 (gmt 0)

    1. Well this rule In /addon_folder/.htaccess works fine:

    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?

    jdMorgan




    msg:3610449
     8:46 pm on Mar 25, 2008 (gmt 0)

    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]

    galench




    msg:3611039
     1:57 pm on Mar 26, 2008 (gmt 0)

    1.

    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.

    Don`t know, but i have this code in main domain, and it`s works fine:

    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]

    Maybe because it`s redirecting first from main folder to http://www.example.com/mainsite/index.php
    But it`s works fine!

    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]

    This why i aded these lines:

    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]

    galench




    msg:3614054
     10:07 am on Mar 29, 2008 (gmt 0)

    Hi JD!
    How are you?
    Because i can`t made redirection in main htaccess, i do it in addon htaccess.
    But idon`t know where i must put "THE_REQUEST" line:

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /addon_folder/?

    In this addon htaccess file:

    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]

    Also is this THE_REQUEST line correct for addon htaccess file?

    jdMorgan




    msg:3614221
     4:16 pm on Mar 29, 2008 (gmt 0)

    The RewriteCond must always stay with the rule that it pertains to.

    I'm sorry, but I cannot answer your questions; Your server set-up is too complicated. I would suggest hiring someone who speaks your native language to help you configure your server to meet your needs.

    Jim

    Global Options:
     top home search open messages active posts  
     

    Home / Forums Index / Code, Content, and Presentation / Apache Web Server
    rss feed

    All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
    Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
    WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
    © Webmaster World 1996-2014 all rights reserved