Consider the following structure:
example.com locates to public_html/index.php
example2.com locates to public_html/SUB/e2/index.php
I want to take example.com down for maintenance, and thought htaccess would be the best method. But then I became worried that doing so would block access to the second (unrelated) site, because to the server it is located within the first site.
Would an htaccess-driven block at example.com also kill off example2.com ?
Isnt there a thing like "priority" in htaccess files?
I mean e.g. you first block the access to "public_html"
and then allow access to "public_html/SUB/e2" etc. ?
Must work i think.
Related
It's hard to explain, I would like to do something like below but I don't know how.
I currently own two different domain names and have one website.
Can I have two domains pointing to the same website but the URL only shows whatever domain is entered in the first place?
For example, when I type in 'domain123.com', it takes me to my website (IP address 111.222.333) with the URL shown as 'domain123.com'. Then when I type in 'domainABC.com', it also takes me to the same website (IP address 111.222.333), but the URL needs to show 'domainABC.com' instead of 'domain123.com'.
I guess I will need to redirect one of the two domains to the website, but how can I stop the URL changes the domain name?
I am not sure if I can just modify .htaccess to achieve above or if I also need to change the DNS, etc. to make this work.
Please help and many thanks
It depends on your setup and your server permissions.
A nice way will be to change the docroot in the apache or nginx config.
If you don't have permissions to edit these configs, you can create a symbolic links so that the public folder of domain2 points to the public folder of domain1
I have two differents domains :
www.domain1.com that points on folder www/domain1
and
www.domain2.com that points on folder www/domain2
I want to share common ressources (php files, images,..) into a third folder www/ressources.
For exemple, the php welcome page is the same for the two domains (just using specific variables that make them different) :
In my .htaccess I tried this trick for domain1 :
DirectoryIndex ../ressources/test.php?dir=domain1 (and then test.php would be loading specific var located in www/domain1/var.php)
and for domain2
DirectoryIndex ../ressources/test.php?dir=domain2 (and then test.php would be loading specific var located in www/domain2/var.php)
This is not working (getting a BAD REQUEST 400), I guess because the htaccess is traversing the root directory of the domain.
What would be the solution, since I am using a shared hosting solution (OVH) and can only modify .htaccess files (I don't have access to underlying OS) ?
Since you don't have access to the server or virtual host config, the primary way of using an Alias directive won't work.
Depending on your requirements you may be able to use a Redirect or RedirectMatch algorithm, which is available for configuration in a .htaccess file.
https://httpd.apache.org/docs/2.2/mod/mod_alias.html#redirect
I have two domains on a VPS server, the primary "domain1.net" and the secondary "domain2.com". The website I have currently set up for domain2.com resides at domain1.net/subd1/subd2. I'm trying to create a rewrite rule for my .htaccess file so that whenever someone visits the site "domain2.com", "domain2.com/index.php", it grabs the page from "domain1.net/subd1/subd2", "domain1.net/subd1/subd2/index.php". I would like to do this while keeping "domain2.com" intact in the web address, instead of moreover redirecting it, and have all images/links appear from domain2.com.
From my understanding, it seems .htaccess's rewrite rule would be able to do such a thing, I just haven't figured out how the syntax would work. However, if there's a superior alternate method, I wouldn't be opposed to hearing it.
I appreciate anyone's help on this issue.
We're looking at running bigcommerce for a website and they have the ability to run the store using your primary domain url (which we don't want to do) or a subdomain. We wanted to have for eg: http://www.ourwebsite.com/shop.
Bigcommerce doesn't have the capability of us running it on a subdirectory, aside from a subdomain.
Can we with dns records point our subdirectory as above to load contents from our subdomain? If so, how?
ie: http://shop.ourwebsite.com/ contents displayed on http://www.ourwebsite.com/shop
We also have to use cname records to make our shop.ourwebsite.com subdomain load the contents from bigcommerce (I assume this is how it's done using your own url rather than their own yoururl.bigcommerce.com url).
We need to ensure this can still remain in place and it doesn't affect the above change we require.
Thanks!
You can:
Use mod_proxy this way your url stays the same (available through mod_rewirte [P] flag).
Redirect to your subdomain (html-meta, htaccess/http reply 301/302, frameset/iframe which is really ugly)
But with pure DNS, it's not possible.
CNAME DNS entries are just aliases for other domains, but can't handle directory structures.
What are the different approaches to securing a directory?
including an index page so contents can't be viewed
the problem with this is that people can still access the files if they know the filename they're after
including an htaccess file to deny all
this seems to be the best approach, but is there any case that an htaccess file can be passed by? are there any cases as well where htaccess is not available?
restricting folder access
this is also a nice solution, but the problem is, the folder I'm trying to secure should be viewable and writable by the program.
Are there any other ways that folder security can be done?
Best practice for Apache is to use htaccess to restrict - this only restricts from the webserver - but that should be what you need. You can add authentication into this - but for most needs to you can just deny all acess - which hides the directory completely.
Another method that can also work well with using htaccess to deny direct access would be to use htaccess in your route directory to rewrite urls. This means that a request such as /example/listItems/username/ted can be rewritten as a call to a php or other file such as:
/application/index.php?module=listItems&username=ted
The advantage of doing this is that the webserver does not give out paths to any directories so it is much more difficult for people to hack around looking for directories.
If you want to protect a directory of images you could also use htaccess to redirect to a different directory so that /images/image5.png is actually a call to :
/application/images/image5.png
You could also try not placing your protected directory under your www dir but on other "non www visible" location. If your app needs to read / write data, tell it to do it on the other location. Modify its properties so only the app has the proper rights to do so.