Making the Document Root dynamic - .htaccess

I have been searching and looking for the answer to this for SO long now without any joy, I hope someone can help.
Okay I have a web structure of:
Main folder - This is where you first land prior to logging in. After you log in you will be either directed to a number of websites that are resident in a sub-folder called websites. The problem I have is that I would like the document root, say the $_SERVER['DOCUMENT_ROOT'] variable, to default to the root of the website folder that it has been directed to. You see I have a lot of $_SERVER['DOCUMENT_ROOT'] in my php code and I use the '/' slash a lot in the href on my HTML tags.
I have seen that I could accomplish this by adding a .htaccess in the root of eiach website folder but 1, would like work for my situation and 2, could anyone please help me with the code. I understand I can use the RewriteRule command but I can't get my head around it. My folder stricture is like this:
login (index.html)
websites folder
website1 (index.html)
website2 (index.html)
website3 (index.html)
I have tried many versions of using RewriteCond etc but non of them work.
If anyone can help me out here I'd be very grateful.
Thanks

Nothing you can do in your htaccess file that's going to be able to change the document root. One thing that you can do is create separate domains that you can make their document roots point to each of the websites folders. Then proxy to one of those domains.
That way the URL on the browser doesn't change domain names, and internally, you're proxying requests back to yourself and the individual website domains will each have their own document root.

Related

htaccess rerouting multiple domains to one subfolder on the same level with a static value pass through

I know there are many .htaccess questions and aswers here and on the internet, but I can't find the answer in all the noise I am looking for. I am on a shared server. If you go to domain abc.com it access folder abc. IF you go to domain def.com it access folder def. What I want is if you go abc.com it must reroute the domain to folder def and send it a static value saying this is from abc... in that way I can have multiple domains access the same code in one folder and don't have to duplicate the code over and over again. Any ideas and solutions and comments will be extremely welcome and deeply appreciated. thanks

How can I display a subpage of my Silverstripe website as a subdomain?

I have a website build on Silverstripe 3.
Now I want that a user can enter the Subdomain URL info.mydomain.com and see the content of the page mydomain.com/subpage-url/. But without redirection. The subdomain URL should stay in their browser.
I already created the subdomain and let it point to the root directory of my website. As I understand it right I now need some rewrite conditions in my .htaccess file? And that is the point I struggle with. I googled a little bit and did some trail and fail but nothing seems to work. Maybe I understand it totally wrong, used the wrong rewrite conditions or insert them on the wrong place.. Maybe there are Silverstripe specific issues to pay attention to?
Long story short: I need help please!
As Robbie Averill pointed out in his comment, you could install the Subsites module. But you'd have to create a Subsite (eg. a separate site-tree) for every domain.
There's another module though, the homepagefordomain module. With that module you can specify one (or multiple) domains per page. When you visit one of these domains, the page that was specified as home-page for that domain will show up. I think this is a more flexible approach than messing with the .htaccess file.

htaccess redirect from two domains

I have two domains, lets say www.A.com and www.B.com which are located on the same server. The directory is like this:
/html/index_of_A.php
/html/content_of_b/index_of_B.php
Now i want to configure an .hataccess file, which does the following things:
1) redirect users which enter A.com to /html/index_of_A.php (which is actually www.A.com) and
2) redirect users which enter B.com to /html/content_of_b/index_of_B.php
At the end, users enter two domain names (a.com and b.com) and they are getting redirected respectively to the specific folders of the domains.
Is that possible with htaccess?
The reason for this is, that i have two domain names, but they are on one server. Now I want to seperate both of them, to make "two different web pages".
Further, the users should always get rediretet to the www version.
Unfortunately I have no idea how to do that... I did some searches and tried different methods, but no success :(
Hope anybody can help me, appreciate that!
If I understand you problem correctly, there is no need to configure an .htaccess file.
You can solve your problem by slightly reorganizing your folder structure.
This is how I would solve it:
[folder for domain A/index.php]
[folder for domain B/index.php]
Configure your domain registration for www.A.com to point to [folder for domain A]
Configure your domain registration for www.B.com to point to [folder for domain B]
This way there is no need for an .htaccess file unless you are setting one up for security reasons (not redirection) AND you don't have to muddle through www.A.com's files when you need to focus on www.B.com.
I hope this helps.

How to add something to start of url using htaccess?

I have seen sites that when you login it will look something like...
.example.localhost/blahblah.php
how is this possible with htaccess?
Any ideas
Do the files have to be placed in a seperate folder??
It's called sub-domain.
It has more to do with the DNS but htaccess can be used to modified its behavior.
Ie, point different sub-domain to the same folder.

.htaccess solution for localhost

I am developing local websites and keep having problems with wordpress sites when they use relative links such as:
<a href="/wp-content/themes/mytheme/myfile.php">
This resolves to my localhost document root (htdocs) instead of the root of the job (htdocs/myjob).
Is it possible to use an .htaccess file in the root of the job (htdocs/myjob) folder to "fix" this behaviour? Or is it possible to put this htaccess file in htdocs, check the HTTP_REFERER, and send the browser to the correct site root?
Can you show me an example of the rewrite rule needed?
Any other suggestions would be welcome too.
In fact you mean absolute links. Relative links are what you want.
You should be able to configure the root directory in your Wordpress setup: this would be the correct approach.

Resources