View Single Post
  #1 (permalink)  
Old 04-11-2009, 09:29 PM
pingram3541 pingram3541 is offline
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