Welcome to WebmasterWorld Guest from 54.224.121.67

Forum Moderators: Ocean10000 & incrediBILL & phranque

How to

     
12:48 pm on Oct 11, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts:1051
votes: 0


When I add Subdomain into public_html it is seen all content also inside main domain.
I need to update a rule in the .htaccess file in the subdomain's document root that ignores the .htaccess entries in the parent directory.

Example:
mySUbdomain.example.com/user/ID

When I check also main domain like example.com/user/ID it will be also the same content as it is inside public_html.

How to solve this as
main domain like example.com/user/ID should not be seen but all PHP and MYSQL should be functional.
1:52 pm on Oct 11, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11080
votes: 106


i am assuming the subdomain's document root is a subdirectory of the main domain's document root directory

http://httpd.apache.org/docs/current/howto/htaccess.html#how
a .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree
4:01 pm on Oct 11, 2017 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 306
votes: 21


There is no universal quick fix for this. It depends on the directives you have in the parent directory's .htaccess file.

However, if you want to ignore just the mod_rewrite directives in the parent .htaccess file (which I suspect is what is being used in order to route a URL like "/user/ID") then you can simply enable the rewrite engine in the subdirectory's (subdomains) .htaccess file. This assumes you have not changed how mod_rewrite directives are inherited in the server config.


RewriteEngine On


If the subdomain is unrelated to the main domain and should not inherit anything from the parent .htaccess file then consider pointing your subdomain to a directory outside of your main domain's document root instead.
11:22 pm on Oct 11, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


Are you trying to say that
subdomain.example.com/blahblah
whose files are physically located inside the example.com directory
should not also be accessible via
example.com/subdomain/blahblah
?
11:31 am on Oct 16, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1051
votes: 0


Yes, I like to eliminate example.com/subdomain/blahblah as it is subdomain.example.com/blahbla as working URL.
11:56 am on Oct 16, 2017 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11080
votes: 106


Example:
mySUbdomain.example.com/user/ID

When I check also main domain like example.com/user/ID it will be also the same content as it is inside public_html.

Yes, I like to eliminate example.com/subdomain/blahblah as it is subdomain.example.com/blahbla as working URL.

these two sets of patterns are inconsistent.
11:57 am on Oct 16, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1051
votes: 0


How to check which mod_rewrite directives is being used in order to route a URL like "/user/ID"?
10:19 pm on Oct 16, 2017 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:14256
votes: 551


Yes, I like to eliminate example.com/subdomain/blahblah as it is subdomain.example.com/blahbla as working URL.

Do you have just a few subdomains, or are there wild-card subdomains with unlimited numbers? Do the subdomains have a predictable name format? Does the primary site also have directories in some of its URLs? Are these requests actually happening, or is it just for insurance?

If it's just a few subdomains--and if the name of each subdomain's physical directory is exactly the name of the subdomain--it goes like this
RewriteRule ^(sub1|sub2|sub3)/(.*) https://$1.example.com/$2 [R=301,L]
That is the best-case solution. It depends on how complicated the site is.
8:17 pm on Oct 25, 2017 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 25, 2006
posts: 1051
votes: 0


I'm not sure right now.

What about general solution.
Redirect just one link to a Not Found page using .htaccess which is to be placed into the mysubdomain domain web root directory:
Basically I like to do to make the links - mysubdomain.maindomain.com but maindomain.com/mysubdomain should be unavailable.
Both can be achieved but not just maindomain.com/mysubdomain unavailable
like general sample:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain.maindomain.com$
RewriteRule ^(.*)$ "http://example.com/404" [R=301,L]
</IfModule>
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members