This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Create Subdomains on the fly with .htaccess (PHP)
for one of my scripts, i want it so that each of my clients has their own subdomain
however, i want each subdomain to use the exact same script, and the exact same database
can this be accomplished with HTACCESS?
example: john.mysite.com would take them to my script, setting a username variable as john...so they can be identified in the database...
how can i do this?
You can set the ServerAlias directive in your VirtualHost configuration to *.mysite.com. You can then use mod_rewrite in the .htaccess to append the username to the URL, or use PHP to pull the subdomain off the requested URL, and do whatever you want with it.
Related
This question already has answers here:
Allowing only localhost to access a folder where all inclusive php files exist
(5 answers)
Closed 5 years ago.
I have lot's of PHP pages in public_html folder. But I want nobody to open them except me. I don't have any registration or anything else. I just don't want anybody access them. Is this possible? Those pages are for getting reports form database.
I've tried .htaccess but not a useful try.
Just include
Option -Indexes
in .htaccess file and save it.
Then nobody will get access to that. Thanks.
The Apache .htaccess file is meant to rewrite responses by either granting or denying access to users based off the request made.
You can use an .htpasswd file in conjunction with you .htaccess file to selectively grant or deny users access to your resources by requiring authentication via a password.
This question already has answers here:
How do I disable directory browsing?
(14 answers)
Closed 5 years ago.
I have a web application developed in PHP.
My requirement is to block a folder which contains uploaded documents.
For example, if a user click a document link on the application, it should open
http://localhost:1987/enterprise_resource_planning/uploads/students/documents/1499866795_100_100.pdf
if a user execute below url, it should block
http://localhost:1987/enterprise_resource_planning/uploads/students/documents/
I've tried .htaccess with Deny from all, but it is blocking everything.
Any solution for this senario ?
possible solutions:
place a file index.html or index.php in the directory
define in your httpd.conf Options -Indexes
place that line in .htaccess
personnally I prefer the 2nd line. There hardly ever is use for automatical listing of the files to a browsing visitor.
This question already has answers here:
What is .htaccess file?
(9 answers)
Closed 5 years ago.
I am creating small data entry software using php with ajax code. But I didn't create .htaccess file. I have one doubt. must we create .htaccess file ? why we create .htaccess file. Please suggest.
A .htaccess file is not mandatory.
It has many uses and if there is a specific need, you have to use a .htaccess file. If not, you can ignore it.
For example with .htaccess you can do redirections, you can do authentication with username and password, you can restrict specific directories and many more uses.
In your case, if your needs dont forward you to the use of .htaccess, just dont use one. Although most websites nowadays have at least 1 need that .htaccess covers.
.htaccess is an Apache config file, it works in hierarchical mode, if you load it in a folder, it apply the configuration to all subfolders.
.htaccess is helpful to set timezone, redirect, customize error pages and enable or disable cache.
It is not mandatory however it is recommended its use.
This question already has answers here:
configure only allow specific domains to access certain folders using .htaccess
(4 answers)
Closed 6 years ago.
I have the following scenario:
I have text, images, videos in my root folder.
The data is sensitive
I would like to:
Limit any public direct access, but I would like to be able to access/copy them from a particular domain like abc.com.
Is this possible using .htaccess, if yes than how?
on the folder you wish to protect create an .htaccess file and put on it
Order Deny,Allow
Deny from all
Allow from Your_IP_ADDRESS
This question already has answers here:
URL rewriting with PHP
(5 answers)
Closed 8 years ago.
I have a file named index.php that contains some code and its directory address is:
http://www.example.com/user/index.php
I want to open this page in the root directory so that user think this is index page like this:
http://www.example.com/index.php
In this way my php file address is www.example.com and not www.example.com/user
What is the simplest way to do this?
This is handled by your web server, not PHP. Check your Apache / IIS / etc settings for DocumentRoot of given VirtualHost definition.
As SGT noted you can also use URL Rewriting, but again, that too is handled by the web server and has nothing to do with PHP.