iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-11-2009, 09:29 PM
WebProWorld Member
 
Join Date: May 2008
Posts: 25
pingram3541 RepRank 0
Default Primary Domain redirect to folder

Ok, I have a Unix style host with apache/cpanel for administration like bluehost, hostgator, siteground etc.

My problem is the same with all these hosts and the dependency to have a primary domain mapped to /public_html but subdomains and addon domains can map to folders no problem.

All these hosts refuse to manually edit the httpd.conf file so I can resolve my primary domain to it's own folder.

I tried using .htaccess to essentially do this for me and I think it would work fine except that my site is written primarily in php which causes the dynamic links to look messy.

for example, I can type:
http://mydomain.com
http://www.mydomain.com
http://www.mydomain.com/index.php
etc, just fine, but all of the links on my site generated by PHP show up with the folder in the path, for example, my about page link looks like this:

http://www.mydomain.com/mydomain/about/

If I manually type http://www.mydomain.com/about in the address bar it works just fine, it's just my links do not omit the folder in the path, which also result in my sitemap and bots crawling my site with undesirable long links.

i.e. here is my .htacces in /public_html/

Code:
# -Begin custom settings
Options -Indexes
DirectorySlash Off
DirectoryIndex index.html index.php
ErrorDocument 403 /403.php
ErrorDocument 404 /404.php
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
 RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
 RewriteCond %{REQUEST_URI} !^/www\.mydomain\.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /mydomainsubdirectorywitinpublichtml/$1
# Add a trailing slash onto directories so the DirectoryIndex search works.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} !/$
RewriteRule ^(.*)$ $1/ [L]
# ...except for /. This one we have to hard code to a specific file.
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ index.php
#End custom settings.
Then in my public_html/mydomainsubdirectorywithinpublic_html/ .htaccess file I added this to turn on clean urls:

Code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mydomainsubdirectorywithinpublic_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Is there any way to keep my site links from showing it is installed in a folder without having to go through all the php code in my site and write custom php stripping code into any possible dynamic links?

Thanks for any and all feedback.
Reply With Quote
  #2 (permalink)  
Old 04-12-2009, 12:41 PM
WebProWorld Pro
 
Join Date: Dec 2007
Location: Brussels, Belgium
Posts: 164
Jean-Luc RepRank 2
Default Re: Primary Domain redirect to folder

Quote:
Originally Posted by pingram3541 View Post
all of the links on my site generated by PHP show up with the folder in the path, for example, my about page link looks like this:

http://www.mydomain.com/mydomain/about/
This is an application issue. It is not PHP or .htaccess related. If you are talking about a WordPress site, go to "General Settings" and check the values of WordPress address (URL) and Blog address (URL). Both should be http://www.mydomain.com.

Jean-Luc
__________________
Checking redirects made easy | | Professional AWStats Services
Reply With Quote
  #3 (permalink)  
Old 04-13-2009, 12:51 PM
WebProWorld Member
 
Join Date: May 2008
Posts: 25
pingram3541 RepRank 0
Default Re: Primary Domain redirect to folder

I actually use concrete 5, a nice and simple CMS but took me some time to figure out it's "hooks".

I found the site.php config file and identified that it needed the install folder defined.

Removing it and relying on my .htaccess file to redirect to the folder took the site down.

I then use DW to search the site for all PHP calls for DIR_REL which seems to be hard coded everywhere for the links. something like:

Code:
echo('BASE_URL', 'http://' . $_SERVER['HTTP_HOST'] . 'DIR_REL', $uri);
which I believe is putting the install folder in all the links. These links are everywhere. I can use DW find/replace of course, but...If I modify the code, future upgrades of my CMS will have to manually edited again.

I did get this resolved but only after pressuring my host support. I basically had them change my primary domain to something non-existant like myfakeprimarydomain.com and then re-added my real domain as an add-on domain into it's own folder.

Then removed the install folder line in my CMS config file, removed the custom .htaccess file in public_html and fixed all my subdomains that had changed due to changing the primary domain via my host company.

My site and some sub-sites were down for about a half hour until I could make the fixes but this ultimately fixed the problem.

In retrospect, it seems like *nix hosts all have this idea of the primary domain being in public_html and add-on/sub domains being in folders, which is fine, but shouldn't it be simpler to have a clean public_html folder if the owner chooses?

And finally, I do admit that this was all my doing because I didn't want my main site files strewn about the public_html folder. I like a tidy place where each site can exist in it's own tidy folder space.

If there is a better way, I'd love to hear about it.
Reply With Quote
  #4 (permalink)  
Old 04-15-2009, 08:05 AM
WebProWorld Pro
 
Join Date: Oct 2005
Location: USA
Posts: 152
onlinetv RepRank 0
Default Re: Primary Domain redirect to folder

When you get hosting you have to have one domain placed in a wrapper of the shared domain host. Then you create wrappers around you, so logically they are in folders below your initial domain. That initial domain claims the set of wrappers you create. It is a hierarchy system just like directories.

I like the same neatness you addressed and for the main hosting domain name I use either a throwaway or put the programs in a folder below public_html.

Edit .htaccess to 301 or 302 all index.php or index.html calls go to the new folder (remove all those rewrites and put them in the folder if needed for the program). Once in that folder uses will use the program like normal - most CMS do not care where you put them and the line of text defining the directories shows that by picking up its variables.

Now you only have the .htaccess, the error shtmls, favicon.ico and a robots.txt in the root dir to pass muster with search engines.
Reply With Quote
  #5 (permalink)  
Old 04-15-2009, 01:38 PM
WebProWorld Member
 
Join Date: May 2008
Posts: 25
pingram3541 RepRank 0
Default Re: Primary Domain redirect to folder

I'm not exactly sure what you mean by "wrapper"? A search on google only led me to canada's domain.com wrapper service which seems to be a custom service they provide for get past the typical 24-72 DNS update period. Still a bit fuzzy on that. I will make a logical assumsion that "wrapper" simply defines the account built on the host for which all add-on and sub-domains are defined within.
i.e. 2 real domains, the primary, 1 sub and 1 addon would actually produce 4 listings in cpanel

primarydomain.com
subdomain.primarydomain.com
addondomain.com
addondomain.primarydomain.com

I assume what you are getting at is a "dummy" domain to be the primary so that all the real domains can exist neatly in folders and creating special .htaccess rewrites isn't necessary. This is basically what I was able to get my host to do without actually registering a dummy domain.

For example, if my real primary domain was:
myspecialdomain.com

and I had 2 sub-domains:
me.myspecialdomain.com
you.myspecialdomain.com

and I had 2 email accounts:
me@myspecialdomain.com
you@myspecialdomain.com

and then I had my host change my primary domain to a dummy domain of:
myfakespecialdomain.com

the resulting change for my existing sites was:
myspecialdomain.com changed to myfakespecialdomain.com
I had to create a new add-on with my real domain which created or in my case used by default the existing folder "/myspecialdomain.com/"

This also added what I assume you meant a wrapper within the wrapper of (auto subdomain that has to exist):
myspecialdomain.myfakespecialdomain.com

Also, my existing sub-domains became:
me.myspecialdomain.com became me.myfakespecialdomain.com
you.myspecial.domain.com became you.myfakespecialdomain.com

I was able to add the real sub-domains back on now that my real add-on domain existed and then delete the XXX.myfakespecialdomain.com for the 2 sub-domains only having to still keep the:
myspecialdomain.myfakespecialdomain.com

and finally, my emails changed:
me@myspecialdomain.com became me@myfakespecialdomain.com

and similar for the you@myspecialdomain.com would become you@myfakespecialdomain.com

In this case, I had to login to the existing "changed" email accounts and forward all mail I wanted to keep to newly created:
me@myspecialdomain.com
you@myspecialdomain.com

In my case, I think the 302 I had setup would have worked but the CMS I used wasn't written the best way and always exposed to installed folder when generating links thus making all links look like:
http://www.myspecialdomain.com/myspe....com/index.php

So the lesson learned in this scenario, before I setup a new host, either:

1) Work with them to see if they can accomomdate a "fake/pseudo" primary domain that can be setup before any applications, sub-domains and email addresses, then setup my "real" add-on domains, etc.

2) Register up a throw-away domain and use that as the primary domain (slightly wasteful)

3) Be wary of the applications I will be using for the primary domain and use .htaccess re-writes to 301 or 302 redirect to the folder I will have my primary domain application installed.

Thanks for all the input.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
New domain vs. sub-domain vs. folder cah23 Search Engine Optimization Forum 10 05-18-2007 02:36 AM
Redirect vs domain name urcleanandlean Search Engine Optimization Forum 3 05-16-2006 04:18 PM
301 Redirect for entire folder? spenland Search Engine Optimization Forum 0 11-02-2005 08:15 PM
ModRewrite: How to redirect [domain].com to www.[domain].com inflectionpt Web Programming Discussion Forum 2 02-12-2005 09:12 AM
what is the best way to redirect one domain to another Yatin Google Discussion Forum 1 09-21-2004 01:11 PM


All times are GMT -4. The time now is 05:05 AM.



Search Engine Optimization by vBSEO 3.3.0