Share ressources between two domains using .htaccess - .htaccess

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

Related

Magento - Multi Website Setup

I am having configuration settings with my multi website magento setup.
I have a website running at abc.com . Now for international storefront I have created another website, store view and store with abc_international as the website code.
In my configuration, I have configured Base URL as abc.com/int/
However, when I access the URL abc.com/int/ it generates a 404 error.
Another important point is even if I specifically make changes in index.php as follows -
$mageRunCode = "abc_international";
$mageRunType = "website";
Mage::run($mageRunCode, $mageRunType);
Any ideas as to what might be the problem.
You need to copy index.php and .htaccess files to abc.com/int/ at server and provide particular path to Mage.php file at index.php which is inside abc.com/int/ and in that index.php file you need to modify Mage::run($mageRunCode, $mageRunType); to Mage::run("abc_international", "website"); then it will work if you properly configured multi-website setup.

Retrieving files from another URL on the server

I have one server two domains. I need the images and css apply to both domains. Currently I solve it using htaccess:
RewriteRule ^.*\.(css)$ http://www.rs.cz/style/$0 [L,R]
How is it possible to improve? Or at least refer to a relative path on the server?
Create one subdomain just for hosting images and static content like:
images.mydomain1.com
and another subdomain like:
images.mydomain2.com
Have both of them redirect to the same directory in the server like /var/www/common_images.

.htaccess solution for localhost

I am developing local websites and keep having problems with wordpress sites when they use relative links such as:
<a href="/wp-content/themes/mytheme/myfile.php">
This resolves to my localhost document root (htdocs) instead of the root of the job (htdocs/myjob).
Is it possible to use an .htaccess file in the root of the job (htdocs/myjob) folder to "fix" this behaviour? Or is it possible to put this htaccess file in htdocs, check the HTTP_REFERER, and send the browser to the correct site root?
Can you show me an example of the rewrite rule needed?
Any other suggestions would be welcome too.
In fact you mean absolute links. Relative links are what you want.
You should be able to configure the root directory in your Wordpress setup: this would be the correct approach.

using htaccess to restrict access on root when subdomains are also present

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.

Fully securing a directory

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.

Resources