I have an issue.I need to get url like subdomain2.subdomain1.domain.in/filename .
I created a subdomain2 under sundomain1 in cpanal its is created like subdomain2.sundomain1.domain.in
But I have doubt on how to create in .htaccess file for sub subdomain.
To give an example:- articles.mydomain.in is working whereas mycity.articles.mydomain.in
is not working..
Can this be done or what I am doing is wrong? When I googled I came to know that it cannot be done in one website,whereas in another website they have mentioned that it can be done,but not given how to procees.Can anyone help?
Your sub sub domain should have its own folder. So you have to put .htaccess file there.
You could check the folder in your apache configuration. (See VirtualHost directive for subdomain2.sundomain1.domain.in).
Config probably located here:
/etc/apache2/apache2.conf or /etc/httpd/httpd.conf
Related
I am writing an HTML/CSS/JS project on my localhost.
The project root is found at http://localhost/projects/project1/.
I want to know if it is possible to make the HTML files treat my project
root as its' base URL so that referencing the same javascript/css files
doesn't depend on the path of the HTML file(unless I reference relative to
current directory).
Here is my project structure:
projects
project1
index.html
pages (directory)
page1.html
page2.html
apps(directory)
app1(directory)
index.html
style.css
app.js
deps(directory)
jquery.js
As you can see, to refer to jquery.js inside my /projects/project1/index.html,
I have to write:
<script src="deps/jquery.js"></script>
To refer to jquery.js inside /projects/project1/pages/index1.html,
I have to write
<script src="../deps/jquery.js"></script>
To refer to jquery.js inside http://localhost/projects/project1/apps/app1/index.html,
I have to write
<script src="../../jquery.js"></script>
At which point I am not sure I wrote the correct number of ../s and can easily
cause errors.
Worse, If i reorder my directories around or rename them, it means I have to deal with
rewriting the paths again, which can be very daunting.
I have thought of various ways to address them none of which are appealing(although option 3 comes close).
Thoughts/Attempts:
I tried playing with .htaccess RewriteEngine/RewriteBase but nothing worked.
I could just create a new server for each project as NodeJS makes it really easy to do so.
This way, each server has the directory as its' static path and is '/'.
The problem with this approach is that this managing
many servers up at once on different ports which can be confusing.
I could set an absolute path variable in .htaccess via
SetEnv PROJECT_PATH /projects/project1/
However doing this means I have to open .htaccess each time I move the folder
or rename it and change the PROJECT_PATH. This may seem simple but if you
give the project to somebody else and they don't know how .htaccess works,
it is very painful to explain how to find this path, and how to change it,
and even more problematic if the .htaccess is longer than one line.
Ideally, I want this SetEnv to figure out the folder it is inside by itself,
but I don't know how to accomplish this. This also has a problem that the pathing becomes dependent on the PHP preprocessing which makes it painful to move to another server that does not have .htaccess or PHP such as NodeJS(which can still invoke php but even then it needs to deal with .htaccess).
I want to know if it is possible to either
Make .htaccess file create an environment variable containing deduced path
of this particular .htaccess file so that php files inside this directory can
do pathing relative to $_ENV{PROJECT_ROOT}. This way if the project is moved or shared, it will still work without needing to modify .htaccess.
Make .htaccess to force HTML files contained in the same or lower directories that all "/" references treat this directory as the root.
Or if there are other things to address this issue that I have not thought of.
Thanks ahead of time.
Dmitry, you can try this:
1) In your file httpd.conf, add the following line at the end:
Redirect permanent /deps http://localhost/projects/project1/deps/
2) Restart apache service
3) Refresh your index page(/projects/project1/pages/index1.html)
I have used something like this:
<html>
<head>
<script src="/deps/jquery.min.js"></script>
</head>
</html>
<?php
echo "welcome to index"
?>
How do I access a directory outside of my document root?
This explain how to give users access to a directory that is outside of your directory root on Windows.
Assuming that your directory is located at C:/www/newfolder/ then you would create the following in your httpd.conf file.
Alias /newfolder/ "C:/www/newfolder/"
<Directory "C:/www/newfolder">
Options Indexes MultiViews
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
Now, when a user goes to www.domain.com/newfolder/ then they see the folder that is outside your document root and it appears in the browser to be a directory contained below the document root..
One thing to consider is that if you have virtualhosts, then an alias works for every virtualhost, so try to use uncommon names for your alias.
Hope this helps
Now I know that you have to FTP the files to the server but I'm more confused about the directory structure... Let me explain..
Here is the localhost directory structure
C:/wamp/www/store/{Here is the entire project}
Here is the online server directory structure
htdocs/{The project will go here}
My problem
As you can see, my root directory for the project is "/store" in the localhost environment. So I used relative path in my code to refer to the root directory which is the "/store/". You can see that I use this type of referencing throughout the project.
print "<div class='globalerror'>
<div class='globalerror-content'>
<h5>Uh-oh! There's an error</h5>
<p>You must go back</p><br/>
<p class='back'><a href='/store/'>Go back</a></p>
</div>
</div>";
If I upload the files to "htdocs" It will give me an error, which is, Directory not found. If I create a folder named "store" inside the htdocs folder... I'd have to go www.mydomain.com/store (which I don't want)
So, did I messed up pretty badly? Or is there a simple fix? Or do I have to edit all the "/store" to "/" in my project?
Simple, You have to change path of directory. Create new directory and give the path of that directory. Because there is no directory in your server.
Currently you can do modify the .htaccess file and can manage urls, change from store to root
Ref 1
Ref 2
Ref 3
The best option is to set the base url in single variable and use the variable around the project.
You can consider the below option, If you are willing to edit the all the links.
settings.php
/*
Local Server = http://localhost/store/
Online Server = http://www.example.com/
*/
$WEBSITE_URL = 'http://www.example.com/';
The php files
Find & Replace /store/ with $WEBSITE_URL , check the single/double quotes
require_once('settings.php');
print "<div class='globalerror'>
<div class='globalerror-content'>
<h5>Uh-oh! There's an error</h5>
<p>You must go back</p><br/>
<p class='back'><a href='".$WEBSITE_URL."'>Go back</a></p>
</div>
</div>";
Have you try URL rewriting with .htacess ?
URL rewriting with PHP
If it possible you could change the Folder inside Apache configuration( i presume you use Apache)
Using a directory in VirtualHost ServerName
I have a CakePHP project uploaded to the server:
httpdocs/cakephp/app/...
My domain name, for example www.mydomain.com is directed to httpdocs/cakephp
Now.. I need to access an image folder that it's otside the webroot of CakePhp:
httpdocs/resources/images/...
The problem is that I can't see files outside the cakephp folder when I go to www.mydomain.com, If I try with ../../resources/images.... I just get www.mydomain.com/resoures/images with an error.
How can I solve this?
Thank you!
Just symlink the resouces folder in your webroot folder.
Alternatively you can send the files through php. The CakePHP book describes this here for >2.3 and here.
Also it is not a good idea to put the whole cake folder in the root of your domain, you should set your app/webroot has the root of your host.
Am trying to use a config file for a database and rating script but the problem is the config file is in this directory :
website.com/include/config.php aka websitename/include/config.php
The rating script needs the config and is accessed like this:
include_once("config.php");
I want the config to be in:
"/files/website/"
A directory level up from the website root folder.
I have been trying with:
"../files/website/" and other variations but can not figure out how to link them.
I have managed to put one config file and access it, but with this ajax rating script the only way for it to work is to have the config in the /include/ folder next to:
rating_process.php - has this link : include("inc/config.php");
rating_functions.php - has this link : include_once("config.php");
rating_total_functions.php - has this link : include("inc/config.php");
Hope i've explained myself here
Right, looking at my hosting now:
$_SERVER['DOCUMENT_ROOT']; outputs this: /foldy/homepages/11/username/htdocs/webbysite
My index file is located at: /foldy/homepages/11/username/htdocs/webbysite/index.php
The included rating script is located in: /foldy/homepages/11/username/htdocs/webbysite/include/
I want the config to be in /foldy/homepages/11/username/htdocs/secretfiles/config.php
Am trying to some how go out of: webbysite folder and then into secretfiles (sibling folders)
I have tried adding ../ and so on, but am missing something obviously :(
Try
$configLocation = $_SERVER['DOCUMENT_ROOT'].'../files/website/config.php';
include_once($configLocation)
but the problem is the config file is in this directory
it is not a problem at all.
just keep it as is.
Concerning your particular problem, your problem is that you don't know where you want to put your file. /files/website/ is not likely a right path and it is apparently not one level high from webroot.
So, first of all make your mind about the right path to the directory and it's relative position to the web root
if you are concerned about security ( because your config file contains the db details ) i would place the db config file outside the site root folder and then require_once('../../dbConfig.php') from the script that's creating xml or json for your ajax
more exactly ...
your site folder might be here: /var/www/html
set a virtual host (done differently on Linux and Windows) and point your domain to a sub folder inside /html so that the new path to the site root is /var/www/html/site.
then place your config file in /var/www/html and call it from your scripts inside your /site folder using require_once('../dbConfig.php)`.
your db details are outside the site folder
I need help in hosting my zendframework project.When i host it i can only view the home page but i cannot navigate to other pages. I think it is something to do with the .htaccess file.
my directory structure looks like this:
.public-html
.htaccess
.myproject
.applicaton
.public
.library
.tests
i will be very graetful for any assistance.
Based on the directory structure you posted, it looks like your .htaccess is in the wrong place. Move it into the public folder and try again. (Your .htaccess file should be in the same folder as your index.php file, per the Recommended Project Directory Structure.)