Laravel treats the /public directory uniquely in that the content is statically served. I have an application which requires this treatment for another folder. How can I emulate the routing-bypass behaviour for an arbitrary folder?
If a file or folder exists and is accessible in 'public' that matches the URI, the webserver will serve that file directly, since 'public' is setup as the document root/web root. If there isn't a match it will pass the request off to 'index.php' which is the front loader for the framework.
Example: For Apache there is a .htaccess file that is in the 'public' folder that directs the webserver to do this and url rewriting.
Related
In my setup i have an apache/php website named test.com and two subfolders, apples.html and oranges.php
So my file system structure is basically this:
html/folder1/apples.html
html/folder1/.htaccess
html/folder2/oranges.php
html/folder2/.htaccess
The problem is that i have a unique domain https://applesandoranges.com and changes needs to do the following:
each request sent to https://applesandoranges.com should be routed to apples.html (a static html app with a specific .htaccess file)
each request sent to https://applesandoranges.com/oranges should be routed to oranges.php that contains a php based web application (with a specific .htaccess file).
Is there a way to this with apache?
i was checking this https://httpd.apache.org/docs/2.4/vhosts/mass.html. but i'm not sure on how to do the setup.
I need to dynamically rewrite urls in Apache by reading the mapped destination url from an alias file (one for each url). Here is my directory structure:
/websites
/.aliases
alias-of-site-1 (file containing 0ad5c94df074c13f)
alias-of-site-2 (file containing 50d9a12e9619d041)
(...)
/0ad5c94df074c13f (website subdirectory for alias-of-site-1)
/50d9a12e9619d041 (website subdirectory for alias-of-site-2)
(...)
When a visitor navigate to http://example.com/alias-of-site-1, I need to read the real subdirectory of the website from the file /websites/.aliases/alias-of-site-1, then rewrite the url as http://example.com/0ad5c94df074c13f
I find the Apache RewriteMap directive, but it only seems to work when all key / values are in one file. In my case, each alias has its own file.
Here is the folder layout.
/outside is not normally accessible anywhere on example.com
/public_html is the folder for http://example.com
How can I use Apache's htaccess to make the url http://example.com/outside/ to show content from the folder /outside?
Thanks!
How can I use Apache's htaccess to make the url http://example.com/outside/ to show content from the folder /outside?
You can't. As far as I have found out, Apache prevents directives in .htaccess files linking to locations outside the current web root.
You would have to do this in the central configuration:
Alias /outside /path/to/your/outside
You may be luckier with a symlink if you can turn FollowSymLinks on.
My web root is /var/www/test/public, eg:http://www.test.local is rewrite to here,
but there's a folder /var/www/test/documents/ where I store some pictures to let others download. How can I config my apache rewrite mod to allow users to download pictures in this documents folder by a url?
Can anyone help me? Thanks!
You don't need mod_rewrite for that. You can use an Alias directive to map that images directory into your document root:
Alias /images /var/www/test/documents
^--web path ^---file system path
That'd make any request for example.com/images be internally redirected to /var/www/test/documents, even though that documents dir is not within your site's webroot.
How do you write rules to redirect all requests to *.php and *.html files in upload/ folder to a text file name forbidden.txt in root www folder. What I'm trying to do exactly is preventing script execution in this dir by redirecting those requests to the text file
Note: The upload/ folder is accessibly by ftp used by a group of people to upload files so I cannot place htaccess inside this folder.
Create an .htaccess file at the root level of your site containing
RedirectMatch ^/upload/.+(html|php)$ http://www.yoursite.com/forbidden.txt
You could also try switching off the PHP engine in that directory by creating an .htaccess file in /upload/ containing:
php_value engine off
although you would need to ensure that people cannot upload files with the name .htaccess
Put your htaccess rules in httpd.conf instead.
If you can't edit httpd.conf, then your best bet is to not allow web access to that directory at all. Let FTP users access a folder outside of your web directory and then provide a mechanism for retrieving the file contents.
You could name that directory "upload". Then you could have your .htaccess file make requests to /upload/myfile execute upload.php, which finds ../upload/myfile and spits backs its contents. This way it would appear to users that they are accessing the "upload" folder directly, but you would the level of control you want through the PHP script.