Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Subdomain to domain re-writing

subdomain rewriting

10:28 pm on Aug 24, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 22, 2009
votes: 0

how do i re-write :

[subdomain.domain.com...] to [domain.com...]
2:02 am on Aug 31, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0

Then I'd suggest that you comment out all lines of the first rule until you have well-defined lists of the subdomains which you do and do not wish to resolve to subdirectories, and conversely, of all subdirectories which do and which do not represent the "file storage areas" for your subdomains. You mentioned "features", "about-us", and "signup" early-on, but did not mention "/images" or "/administrator" until the 29th post in this thread...

Please refer to the resources listed in our Apache Forum Charter, and to the description in that Charter of the purpose of this forum. Once you have studied those references and compared what's in them to the commented code posted here, you should be able to modify the code to do exactly what you want.

2:49 am on Nov 2, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 22, 2009
votes: 0

Hi Jd Morgan,

I have been using : #################BEGIN RULES ON LIVE SITE
# Externally redirect direct client requests for subdomain-subdirectory URLs which
# resolve to existing subdirectories back to canonical subdomain root URLs
RewriteCond $1 !^(features|terms-of-service|about-us|signup|media|includes|modules|cgi-bin|templates|xmlrpc|language|libraries|plugins|administrator|component|images)
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([a-z0-9\-]+)/[^\ ]*\ HTTP/
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule ^([a-z0-9\-]+)/(.*)$ [$1.example.com...] [R=301,L]
# Externally redirect requests for /features, /about-us, /signup, /images in subdomains to main domain
RewriteCond %{HTTP_HOST} ^([a-z0-9\-]+)\.example\.com
RewriteCond %1 !^www\.
RewriteRule ^(features|about-us|terms-of-service|signup|component|includes|media|cgi-bin|templates|xmlrpc|language|modules|libraries|plugins|administrator|images(/.*))$ http://example.com/$1 [R=301,L]
# Externally redirect all www hostnames to non-www hostnames
RewriteCond %{HTTP_HOST} ^(([a-z0-9\-]+\.)*)www\.(([a-z0-9\-]+\.)*)example\.com
RewriteRule ^(.*)$ [%1%3example.com...] [R=301,L]

I notice google is indexing my subdomains with the /index.php even though i have a rule in robots.txt to block /index.php in the subdomain and main domain.

Is there a rule that can check if there is a subdomain redirect to the subdomain such as [one.example.com...] redirects to [one.example.com...] only

I had this rule to redirect index.php to main domain

#RewriteCond %{THE_REQUEST} ^.*/index.php
#RewriteRule ^(.*)index.php$ http://example.com/$1 [R=301,L]

But what i need to know is to run the rule once its in a subdomain and also not redirect to something that would prevent me from going into the backend

The index.php rewrite rule above prevents me from using:

http://example.com/admin/index.php because it would redirect to
This 32 message thread spans 2 pages: 32

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members