I am hosting multiple websites on the same server. Instead of uploading the (same) pictures for each website into individual folders, I would like to make ONE main folder on the server where all websites will get their image from, so I dont end up with duplicates.
I tried everything but cannot seem to get it working. Can anyone help me out?
Hosting on Ubuntu 16.04 with Apache2.
My host file:
Alias "/product-image" "/var/www/uploads"
<Directory /var/www/mysite.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
So basically what I want is when my SRC goes to:
mysite.com/product-image/ferrari/f1.jpg
it should be served from
/var/www/uploads/ferrari/f1.jpg
Tried multiple tutorials but nothing worked so far.
P.S. when I go to the url mysite.com/product-image I would expect to see my upload folder but I see nothing. Instead I get an error:
Not Found
The requested URL /product-image was not found on this server.
Apache/2.4.18 (Ubuntu) Server at bedrijfskledinggroothandel.nl Port 443
If you have your multiple websites set up as subdomains in your hosting (as I do), each website at run time can only see the files in or below its specific subdirectory - the hosting will put this layer of security in place.
If this is your own server, not externally hosted, the same may well apply but you may perhaps be able to override this element of the configuration (if you want to - to me, the reason for this security layer is to prevent users realising the stuff is in the same place and trying to take advantage of the fact in some way).
You could however get to what I think is your objective by putting a http (not file level) redirect in place (via .htaccess) so that the subdomain interpreted https://my-website.com/Images (or whatever) as https://www.my-main-domain.com/central-image-directory, which would do the trick I think.
Related
I used this command to startup ngrok for a laravel site, namely testsite.local:
ngrok http -host-header=rewrite testsite.local:80
I have testsite.local defined in /etc/hosts to map to 127.0.0.1
This works, Ngrok starts up just fine and now serves the local site on some random *.ngrok.io address, which I can access. But all URLs within the laravel application (e.g. internal links, or urls for loading a css or js file) are absolute urls to my locally defined domain, like http://testsite.local/news, or http://testsite.local/css/styles.css. In other words, I can load the site fine, but anyone else just sees a bunch of unstyled html and gets a non functional site.
This has to be a general issue for anyone who uses ngrok and has absolute URLs within their project, but google didn't yield anything useful.
Two possible approaches come to my mind:
rewrite all links in the application to be relative instead of
absolute (oh god please no)
any client that wants to access my site via the *.ngrok.io url has to map the 'testsite.local' domain within their very own /etc/hosts file to the ngrok.io url.
The approaches may work, but this seems so far stretched... isn't there anything else one can do?
SOLUTION
https://stackoverflow.com/a/54488972/718980
You need to use Apache Module mod_substitute.
First, enable module:
a2enmod substitute
service apache2 restart
Then, add the following to the .htaccess file:
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|<your-local-link>|<your-ngrok-link>|in"
More information: https://httpd.apache.org/docs/2.4/mod/mod_substitute.html
In xammp/apache/conf/httd.conf
DocumentRoot "C:/xampp/htdocs/{your-project-path}"
Directory "C:/xampp/htdocs/{your-project-path}"
In the httpd.conf set your DocumentRoot and Directory to the path of your project.
DocumentRoot "C:/xampp/htdocs/projectName"
<Directory "C:/xampp/htdocs/projectName">
I was starting to implement mod_rewrite rules on my site when I came across some weird behaviour. I removed my htaccess file for this test, to take it out of the equation.
My local dev site is at http://dev.mydomain.com and is a virtual host.
If I go to, eg "http://dev.mydomain.com/blog/", that folder doesn't exist, but apache finds a matching php file "blog.php" and instead displays that.
This only happens when there is a matching php file - when there isn't, eg "http://dev.mydomain.com/barfblurg/" I just get a 404.
It's like there are some extra mod_rewrites going on above where the site htaccess would be - that when /file/ couldn't be resolved, it searches for other matching files and instead serves this - but there are no other htaccess files that would have an effect, so this must presumably be a config thing? I can't see anything in the apache.conf or php.ini that would cause this behaviour.
(This also doesn't happen on my live host elsewhere, so it's definitely a config thing.)
Anyone point me to where to turn that behaviour off, because it's interfering with the url rewrites I want to do?
(Apache2, OSX, 10.10.5)
This behavior is due to enabling of option MultiViews.
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
To turn this off use:
Options -MultiViews
at top of your .htaccess or in Apache config/vhost file.
I had a website I designed in the Yii framework. I had to move it over to a new Mac because the old one was dying. I moved everything over, but I cannot access the webpages from the browser, I get a 403 forbidden error. I CHMOD'ed the files to see if that would help, but to no avail. I cannot seem to find the answer on the Yii forums, either. Seems NO files on this site can be accessed even though file permissions are wide open. I cannot seem to find anything in htaccess or httpd that helps. Any ideas on how I tell Yii/Apache that it's ok to serve these pages?
EDIT:
So I see this in the apache2 error_log file:
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /Users/me/Sites/website/index.php
Weird. When I uploaded the site from my old computer to the web I never got any 403s but on this mac only I get this.
I am a CI newbie. All this time i have been doing my recent projects on my localhost. I chose CodeIgniter and Doctrine as my database framework.
My local host specs are:
Windows 7
Wampserver 2.0
I also have rewrite_module enabled in my apache.
Right from the beginning everything was working fine with CI and Doctrine on my localhost. I managed to finish my project and was happily waiting to port my first project live and uploaded it to a subdirectory of my bluehost account.
Before transferring the files i changed the config.php and the database.php by filling the required values.
But after i uploaded my files(along with the .htaccess) to my hosting solution provider i could see nothing but the 404 error (This is from codeigniter class and not my hosting solutions page). I keep getting this. I tried multiple options but i am not able to figure what this is all about. I am sure the index.php is getting called and when it tries to route to the default controller (which is 'home' in my case) it fails for some reason.
The directory structure in my localhost
PathtoWamp->www->mysitefolder
The directory structure in my live site
public_html(this is my root folder)->mysitefolder
I could also see that rewrite_module has been enabled with my live server (Thats wat my hosting solution bluehost says and i guess this is true)
Since i am very well past the deadline, i am wondering for a solution. Kindly do let me know if any of you guys have any idea.
Thanks in advance.
Regards,
Ashok Srinivasan.
I found out the root of the problem. All this time it was not the .htaccess, not httpd.conf and not bluehost, it was not god not anyone but the real culprit was Mr.CodeIgniter.
If you look at the Router.php located inside system/libraries then you will find a line at number 88 where
$this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : strtolower($this->routes['default_controller']);
if you notice at the end of the ternary they are forcing a strtolower operation on the controller name. I removed that method and simply let the original name be used at this point by changing the line to this.
$this->default_controller = ( ! isset($this->routes['default_controller']) OR $this->routes['default_controller'] == '') ? FALSE : $this->routes['default_controller'];
Ok but what is the big deal here? Yes this makes a lot of sense right now. My local server was wamp installed on Windows and my production server was hosted on an Unix box. Since it is very well known that Windows is a soft guy who does not mind much about case sensitivity but Unix is very particular on the contrary.
The controller names in my project were all in Capitalized mode, the real issue arised from here. Also i went to my routes.php lying in the application/config where i rectified issues of this perspective.
Finally i am able to host my site now. Thanks to all who had put their heads into this after reading my question.
Regards,
Ashok Srinivasan.
I had the same problem in your httpd.conf
you need to find a line like this
<Directory />
Options Indexes FollowSymLinks
AllowOverride None
</Directory>
Change it to
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
Thats all it took for me
I need to create custom urls for my users, for ex: www.example.com/alpha, www.example.com/beta. I was creating symlinked directories, which I think worked as a good starting point for prototyping. However, now I need to do this at a scale, running on several web servers behind a load balancer. I am not sure on the right way to do this.
If you are running on an Apache server and you have access to .htaccess files then try this in a .htaccess file
RewriteEngine On
RewriteRule ^(.*)\.html$ index.php?p=$1
This will point all URL's to index.php?p=* internally.
A user will see the .html, and the server interprets it as the pointed url.
Example: yourdomain.com/cocacola.html -> yourdomain.com/index.php?p=cocacola