I need to access to some static files in a folder from different domains. I've think that, instead of make several copies of that folder in each domain public folder, I could make some type of redirection or hard linking in apache for redirect them.
For example, I could access the common static files from www.abc.com/static/* and www.def.com/static/*, and internally, both urls point to the same folder "/home/static/*", transparently for the user and the browser.
You are looking for Alias.
What you want to do, however (creating an alias pointing to a directory outside the web root) needs to be done in the central configuration.
Alias /static /var/www/shared/static
Related
I've tried searching for my exact issue and couldn't find it. I don't want to redirect to a different domain, I merely want to achieve the equivalent of Alias in .htaccess. I'll explain what I have.
I'm using SiteGround cloud hosting and don't have access to anything other than .htaccess files. I have the following directory structure:
/var/www/company.com
/var/www/microsite
company.com contains a Drupal installation. I could create microsite as a sub-directory there but I want to keep the content and code separate.
On an in-house setup I have access to sites-available and have simply created an alias on "/microsite-name" "/var/www/microsite" and all is great - https://www.company.com/^ opens the main Drupal site, whilst if someone opens https://www.company.com/microsite-name content is loaded from /var/www/microsite.
But with this cloud hosting, alias isn't allowed in .htaccess, so how do I achieve the same in .htaccess?
Thanks!
I've setup a VPS with apache2.
I am using cloudflare for DNS management.
Now, I have my websites's files in "var/www/website" folder. Inside that, there is another folder for forum. like "var/www/website/forum" inside which there are all forum related files.
Now, suppose I have www.website.com pointing to "var/www/website"
and I also have a subdomain forum.website.com pointing to "var/www/website/forum".
What I want to do is make the files inside "var/www/website/forum" accessible via subdomain only. I don't want users to access forum via www.website.com/forum, but I want them to access it only via "forum.website.com"
What you need to do is set up what's called a virtual host. You would put your forum at /var/www/forum and website at /var/www/website.
inside /etc/apache2/sites-available, you'll need to add an additional configuration file for that site called forum.website.com.conf.
You'll then need to create a symbolic link to /etc/apache2/sites-enabled for that file so that apache sees it. From there, you reboot the server and are good to go.
Here's some documentation:
http://httpd.apache.org/docs/2.2/vhosts/
http://httpd.apache.org/docs/2.2/vhosts/examples.html
https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
This may be a bit different depending on the flavor of linux, but should be about the same. Control panels like Cpanel, Plesk and WebMan can make this process a bit easier by abstracting the configuration to a web control panel.
Hope this helps you.
Is there a way to do this? I'd like for my assets to be served from a different document root, and I'm not sure if Apache has directives for that.
To serve whole directories from a different location, there's Alias:
Alias /assets /path/to/assetsdir
works in httpd.conf only, though, if you want to point outside the web root.
For specific files there is AliasMatch.
I am trying to achieve something that I am not sure if htaccess can even do.
What I have is a folder structure:
myapp
some_folder
some.js
www
css
js
now the web root is pointing at www folder so i can do http://mydomain.com/js/jquery.js and it would work but what I want to do is http://mydomain.com/myapp/some_folder/some.js and it should load some.js and serve it.
Is it possible to do this in htaccess?
AFAIK, you can't point to directories outside the current web root from within .htaccess.
There is the Alias directive but in the .htaccess file, it works only below the web root. It would have to be in the central configuration file to accept absolute paths.
As far as I know, this limitation applies to all other directives that could help here, too (RewriteRule etc.)
The only workaround that comes to mind is using symlinks. Whether you can do that, heavily depends on your operating system and access to the server.
you can redirect upwards, just using the .. parent directory identifier.
for example:
RewriteRule (.*) ../$1
but only if the destination still lies within your webroot.
in your cas it seems not to, so your only chance is to create a symlink/hardlink to that directory or do some file including
alias rewriting in your server cfg file however would work.
I currently have css and javascript file calls (amongst other things) like the following:
href="/css/default.css"
src="/js/ui_control.js"
putting the preceding / in to make the files relative to the root.
This works great when my page is in the root of the domain.
However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username
As such, all file calls are trying to be called from HOST-IP/css/default.css etc instead of within the ~username sub-folder.
Of course I can wait until the domain name servers propagate but that's beside the point.
How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?
Any ideas?
I'd suggest changing the references in your HTML to the files to be relative, as this will work either in a sub folder or as the root of the domain.
This works great when my page is in the root of the domain. However, I'm currently in the middle of transferring my site to a new hosting provider and as such have a temporary URL which is: HOST-IP/~username
How would I go about writing a rule in the .htaccess file that would redirect all file calls that start with a /, from going to HOST-IP/FILE-CALL, and instead to go to HOST-IP/~USERNAME/FILE-CALL. ?
Unless you can put a .htaccess at HOST-IP/.htaccess on the new server, you can't do this with .htaccess. It sounds like you're on a shared host, so any approach that'd let you do this with .htaccess would allow you to hijack everyone else's site on the server.