How Change Subdomain Root Folder to Public_html via .htaccess? - .htaccess

I have a subdomain that I want to make the root folder to "Public_html",
for example, my root subdomain is
- /public_html/subdomain
So I want to change that path to just /public_html/ for my subdomain. I know it can be done with .htaccess, but I dont know how to do it. Thanks...

I don't know exactly what you want, but here are my two answers:
Answer 1: You want your DocumentRoot to point to public_html
In this case add/change the DocumentRoot in your (virtual) host config of your webserver (I'm assuming you're using Apache, which would be /etc/httpd/conf/httpd.conf or /etc/httpd/conf/extra/httpd-vhosts.conf or even /etc/apache2/sites-enabled/yourhost)
Answer 2: You want to redirect from your subdomain folder to the root of public_html
This is not possible via a simple RewriteRule due to the fact, that your host is pointing to the subdomain folder. The other way round would possible (redirecting from public_html to subdomain).
What you can to is to create a symbolic link from subdomain which points to public_html or a file in it - but I don't recommend this.
Furthermore resources:
A brief description on how to forward to a subfolder using Rewrite rules
Another brief description about the DocumentRoot

Related

Pointing subdomain to public_html

I would like to have the following:
maindomain.com pointing to public_html/subfolder
PLUS
subdomain.maindomain.com pointing to public_html
I managed to do the first on htaccess but don't know how to do the second.
Rewrite role in Apache can be helpful. take a look at the following question:
.htaccess rewrite subdomain to directory

Subdomain Points to Subfolder and need .Htaccess to Redirect to a Wordpress Multi-Site Sub-Site

Ok, since a subdomain has to point to a real place, I created the subdomain pra.aquizone.net to point to aquizone.net/blogs/links/pra. The Wordpress (WP) Multi-site (MU) that I want to point to is aquizone.net/blogs/pra where that directory is virtually handled by the WP MU and the .htaccess under aquizone.net/blogs.
I am assuming that I can change the .htaccess file under aquizone.net/blogs/link/pra to point to aquizone.net/blogs/pra and have the subdomain wind up resulting at aquizone.net/blogs/pra. Only everything I have tried does not work. Here is my currect .htaccess file:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine On
RewriteRule ^pra.*$ http://aquilone.me/blogs/pra/ [R=301,L]
The AddHandler was placed there by the subdomain creation and taking it out or leaving it makes no difference. It does not work. You can go to http://aquilone.me/blogs/links/pra/ and see it does not redirect.
How can I change this to work correctly?
Well, depending on your provider, you can point your subdomain towards the same directory of your top level domain, i.e.:
example.com -> /public_html/
this.example.com -> /public_html/
But your question is not clear about what you are trying to do. Is it a subdomains network or is it a subfolders network? If subdomains, try to change the directory your subdomain points to as in the example above, and create the blog inside wp-admin/network/ If subfolders, then you don't need the subdomain, unless you really want to redirect it to a subfolder just like an easier to remember shortcut, in that case you don't need a RewriteRule, WP takes care of the virtual subfolder.
I figured out what had happened. Anything from the aquizone.net/blogs forward was being handled by Wordpress and the .htaccess setup at this subfolder. Therefore, having the redirect point to aquizone.net/blogs/links/pra and in that folder have the .htaccess to then point it where I want was never being seen.
To fix this, I moved the "links" directory to aquizone.net/links. Placing inside the ./pra/ folder with the .htaccess file. The subdomain redirects to this folder and then the .htaccess redirects this to the correct wordpress multisite subdirectory.
Of course it would be immensely easier if you could access a multisite by a hard link (for example aquizone.net/blogs/index.php?id=2) and could set the subdoman to redirect directly to that. But what I have is working.

How to disable effects of .htaccess within a subfolder if there is a .htaccess file in root?

In my application I have separate spaces for user and admin like
if www.example.com is my website, then www.example.com/admin is my admin URL.
I am using a .htaccess file in my root, and it affects some of the functionality in my admin folder, which I don't want to.
For example, consider below is my folder structure
..
.htaccess
index.php
admin
So if I don't want the .htaccess rules to apply within the admin folder, is there any way?
For people that don't have direct access to httpd.conf (shared hosting for example), just put another .htaccess file in the subfolder and set to the desired behavior.
You should be able to do this, but it does require write access to the httpd.conf configuration.
If you have access to the httpd.conf file, something like
<Directory /admin>
AllowOverride None
</Directory
should do the trick.
Also, note that using .htaccess files in the root directory (as you said you did) is not a recommended approach. You'd be better off moving the contents of the htaccess file into the proper contexts of the httpd.conf file.
More information can be found at http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

make all subdomains access website root files

Here's what I want to do:
Let's say i have www.mysite.com and it's a complex website with alot of files
I want to make fr.mysite.com, it.mysite.com, uk.mysite.com to access the file in the root website (ie: fr.mysite.com/jobs.php will actually load mysite.com/jobs.php but in the browser url it will show the link with subdomain).
I want to build a site with content from multiple countries and I want each country to be accessed with it's code as a subdomain. If I can do that I can then process the url in php and know what country code it's in the url.
Copying the entire site to each subdomain folder isn't an option.
Let me know if you have any idea on how to do that, I guess it's a .htaccess thingy but I can't figure it out .
Use ServerAlias in your VistualHost configuration: set it up as single virtual host where all sub-domains point into the same root folder:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias *.mysite.com
DocumentRoot "\path\to\your\site\"
...
</VirtualHost>
This is the most recommended way -- no need to involve URL rewrite here.

Relative file path issue while using Apache rewrite rules

I am trying to create some Apache rewrite rules that shall be able to route URI requests like e.g.
http://mydomain.com/articles/example to
http://mydomain.com/index.php?site=articles&page=example
What I've got so far is this:
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z0-9_]+).html$ index.php?site=$1&page=$2 [L]
RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z0-9_]+)$ index.php?site=$1&page=$2 [L]
Since I am using relative file paths everywhere in my index.php, for style sheets, scripts, images and the like, I am facing the problem of incorrectly resolved absolute file paths.
For example when I am in the root, http://mydomain.com/ or http://mydomain.com/articles, all relative image paths resolve correctly - images/logo.jpg becomes http://mydomain.com/images/logo.jpg or htdocs/mydomain/images/logo.jpg respectively.
When I click one of my links on the site, e.g. http://mydomain.com/articles/example, Apache (or the Browser?) assumes all my images are located here http://mydomain.com/articles/images/ - it is pretty obvious that this path doesn't really exist.
So here are my questions:
1. Is it possible to solve this problem without changing all my relative file paths to absolute ones?
I could use root / for all my paths on my actual web server, because my domain is advantageously linked.
mydomain.com is linked to /html/mydomain on my web server - / resolves to mydomain.com/, but on my personal computer I am running XAMPP and / resolves to htdocs/ - it should however resolve to htdocs/mydomain/ simply because I hold several sites in htdocs
Absolute file paths are terrible when updating index.php to my web server, because I have to auto-systematically replace path declarations - not only in index.php, but style sheets and scripts as well.
2. Should I create a static DNS entry on my personal computer to adapt to my web server?
3. What is the most commonly used method?
Thank you in advance!
Sincerely, Sebastian
I figured it out by myself, by editing Windows' hosts file and the Apache's httpd-vhosts.conf file.
1. Adding a new static DNS entry to %SystemRoot%\system32\drivers\etc\hosts
127.0.0.1 www.mydomain.local
2. Appending a new virtual host entry to %ApacheInstallDir%\conf\extra\httpd-vhosts.conf
<Directory "E:\htdocs">
Order Deny,Allow
Allow from all
</Directory>
NameVirtualHost 127.0.0.1
<VirtualHost 127.0.0.1>
DocumentRoot "E:\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost 127.0.0.1>
DocumentRoot "E:\htdocs\mydomain"
ServerName www.mydomain.local
</VirtualHost>
Now http://www.mydomain.local leads to htdocs/mydomain directly
3. Changing all relative paths and links in my index.php by simply "rooting" them with a / in front of them, e.g. <img src="/images/logo.jpg" />
I also managed to set up a Site in Dreamweaver, so I am able to use the Design- and the Live-View correctly.

Resources