The folder "www" doesn't seem to work properly on hostgator - apache

I've developed a website using Yii framework and now I need to move it to hostgator cheap hosting for a single site. It looks like it expects that the website must be placed into the root folder but my website has a www folder with index.php and resource files like js,css,images,etc. Also this folder contains a file htaccess with following content:
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
But I suppose I have to add another htaccess into the root folder so all requests will redirect to the www folder. (I did it and tried different combinations of the rewrite rules but they didn't work properly). I'm guessing I should remove htaccess from the www folder and leave only one in the root folder.
Sorry guys, I always have problems with htaccess even after reading documentation.
Thanks in advance.

I think that you can configure your domain as an addon domain with the document root set in www as you prefer.
Of course I am presuming that you have cPanel on Hostgator.

Related

Change document root folder in shared server with .htaccess

I'm the admin of an apache server (on a hosting package that allows me to host multiple domains), I've got one domain in public_html (let's call it www.ROOTwebsite.com) and 9 other domains hosted in a folder in the same directory level as the public_html, called DOMAINS.
So the structure is:
-DOMAINS/site1.com/
/site2.com/ ... etc
-public_html
I'm using '/' in the beginning of all relative paths in wamp for site1.com (for example /menu.php) and it works fine, but when I upload to DOMAINS/site1.com/ it messes up the site because it obviously is looking at the public_html directory as the ROOT.
I've used a number of combinations on the following in the .htaccess file, but I can't figure out which is the right syntax to change the ROOT to a directory sitting NEXT to public_html, not under it as usual:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.ROOTwebsite.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^ROOTwebsite.gr$
RewriteCond %{REQUEST_URI} !DOMAINS/site1.com/
RewriteRule (.*) /DOMAINS/site1.com/$1 [L]
I wish to change the root directory for site1.com so that it also works with the '/', without affecting the public_html website.
Can anyone see the problem with the code above?
You cannot redefine the document root via .htaccess. You have to create different vhosts for the domains that then can have separate document roots.
The closest I have come to redefine a document root via .htaccess is the following (not exactly what you are asking, because in my example, site1.com is a subdir of the main document root, but this would achieve what you want, with the caveat below).
RewriteCond %{HTTP_HOST} ^site1.com$ [NC]
RewriteRule !^site1.com/ /site1.com%{REQUEST_URI} [L,NC]
this will effectively redirect all site1.com to the site1.com subdirectory.
[caveat] The only problem I could not solve is how to redirect an url that goes directly to the subdirectory such as http://site1.com/site1.com/index.html to http://site1.com/index.html

Blocking access to a folder through http

I hope this question is not redundant, but I could not find any answer to the exact question I am asking.
I own a multiple site shared hosting plan on a Linux server.
The hosting plan refers to a domain that we can call www.domain1.com
Every other domain is hosted as a subdir of the main domain. so for example domain2.com will be hosted like: www.domain1.com/domain2.com/
It could be reached using that path or using www.domain2.com directly.
I want to disable the access to domain2.com as subfolder of domain1.com.
I suppose I need to put a .htaccess file in every subfolder of domain1.com which is hosting a website. Am I correct? What do I have to put in the .htaccess file?
thank you in advance,
Max
Put these rules in the htaccess file in domain1's document root (the parent folder):
RewriteEngine On
RewriteCond %{HTTP_HOST} domain1\.com$ [NC]
RewriteRule ^(domain2\.com|domain3\.com)/ - [L,F]
Where the domain2\.com etc are the subfolders that you don't want to be able to have direct access.
However, if you have rewrite rules in each of those subfolders, then you do need to add rules in each of the subfolders:
RewriteCond %{HTTP_HOST} domain1\.com$ [NC]
RewriteRule - ^ [L,F]
The F flag will cause the request to return a 403 Forbidden.

Setting up Drupal and Wordpress under a single document root

I have a hosting account which provides me a folder to publish my files for my domain (say www.example.com). I have set up Drupal for www.example.com with .htaccess at the top folder to enable clean-urls for the Drupal installation. Now I want to have a Wordpress installation under www.example.com/blog/ and have clean URLs for that blog. But while using .htaccess it is not working ok as the .htaccess at the top folder will override the sub-folder one. How to achieve what I intend to?
This really depends on the exact content of your respective .htaccess files.
One workaround is to add a RewriteCond to the head of the main .htaccess file that, if the request URI matches the sub-directory, stops parsing:
RewriteCond %{REQUEST_URI} ^/blog
RewriteRule .* - [L]
this should lead to the blog URLs being parsed properly, based on the rules specified there.

Why is my .htaccess file redirecting to full server path instead of relative path?

I've never had a problem with cakePHP before, but something's odd about this server and is causing the redirects in the .htaccess files to behave oddly.
CakePHP uses mod_rewrite in .htaccess files to redirect requests to its own webroot folder. The problem is that the redirects are listing the wrong path and causing a 404 error. My CakePHP application, which is stored in the listings directory, has a .htaccess file as follows:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [R=301,L]
RewriteRule (.*) app/webroot/$1 [R=301,L]
</IfModule>
(*note that the R=301 causes an external redirect so we can see what is going on from our end. It should really omit this flag and do the redirect internally, transparent to end-users)
This is supposed to redirect any request from http://hostname.com/~username/listings/ to http://hostname.com/~username/listings/app/webroot/
However, rather than simply adding “app/webroot/” to the end as it is supposed to, it is adding the full server path ( /home/username/public_html/listings/app/webroot/ ) resulting in the final URL http://hostname.com/home/username/public_html/listings/app/webroot/ which is obviously incorrect and triggers a 404 error.
The hosting is on a shared hosting account, so that limits what I can do with the settings. I've never seen this happen before, and I'm thinking it's something wrong from the hosting side of things, but if anyone has some helpful suggestions then I can put them to the hosting company as well.
The solution to your question can be found towards the bottom of this page in the cakephp book:
For many hosting services (GoDaddy, 1and1), your web server is actually being served from a user directory that already uses mod_rewrite. If you are installing CakePHP into a user directory (http://example.com/~username/cakephp/), or any other URL structure that already utilizes mod_rewrite, you'll need to add RewriteBase statements to the .htaccess files CakePHP uses (/.htaccess, /app/.htaccess, /app/webroot/.htaccess).
I've deployed CakePHP from my profile's public_html folder as well. I had to change 3 the same .htaccess files mentioned above. Just add RewriteBase /~username/ to the .htaccess files just after RewriteEngine on!
Try removing .htaccess from main file... It worked for me
It was quite simple (using uolhost shared host):
Edit both .htaccess files:
/webroot/.htaccess
/.htaccess
Add the following line:
RewriteBase /
Here is the whole /webroot/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

serve with apache all paths under a domain through one script

i'm hosting a website through a hosting company [1] on a linux/apache server. until now i serve the different content through one script with parameters. an example url is
www.mydomain.com/pages.php?date=1-10-2008
now i want to change the scheme the url is composed of to something which looks completely like a path url. eg.:
www.mydomain.com/pages/date/2008/20/1
for this i need to switch off the normal mapping of url paths to directory folders in apache: all requests to all paths should go to one central script (pages.php), which than analyzes the path component of the url.
how do i tweak apache for this? i hope some .htaccess rules could the trick.
[1] btw, the hosting company is godaddy.com.
Something like:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . pages.php
should rewrite every request for a file or directory that doesn't exist to pages.php. This will allow you to keep static files (images, stylesheets, etc) in the same document root.
(Shamelessly stolen from WordPress :) )
You are looking for mod_rewrite. Example htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^pages/([^/]*)/(.*)$ pages.php?$1=$2
Rather than parse the url in your script, you should be able to handle the specific example above with Apache's ModRewrite module.
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
You can use these in the .htaccess file, assuming your host allows this.