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.
Related
Does anyone know how I could achieve the following with .htaccess?
If the file does not exist but folder exists, redirect to folder
If the file is in the root directory, or folder does not exist, redirect to home page "/"
For example, if we have to take a request to www.domain.com/folder/file.html:
If /folder/file.html exists, we just show it as is, no redirect.
If /folder/file.html does NOT existing but /folder/ does exist, we redirect to /folder/
If then /folder/ does not exists we redirect to "/" We need this done in a generic way so that we do not need to hardcode the folder or file names into the .htaccess file.
Should work for all file types with a way to set up exclusions (both for folders and filetypes)
So here's my directory structure:
|--public_html Dir
|--index.php File
|--search.php File
|----assets/ Dir
|----acp/ Dir
|------assets/ Dir
What I need is a .htaccess way of doing the following:
Redirect http://example.com/ --> http://club.example.com/ (Where club
is not a sub directory, it doesn't exist on the server)
Redirect all pages the same way: e.g. http://club.example.com/search.php
Redirect the /acp/ directory and it's files like this: http://club.example.com/acp/post.php
Redirect the /public_html/assets/ directory too but my javascript files, css files and images are there. I should be able to access them like this: http://club.example.com/assets/theme/reset.css , etc.
The same goes for /acp/assets/ directory. It contains the styling and scripting for the admin page so I need to access files inside it like this: http://club.example.com/acp/assets/scripts/menu.js
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.
I need htaccess that will redirect users accessing subdirectories of specific directory (one that contains htaccess) to corresponding subdirectories on another server.
For example:
server_1/dir_with_htaccess/user_subdir_of_choice ---> server_2/user_subdir_of_choice
No subdirectory woudl actually exist on first server, it woudl just contain htaccess.
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.