I installed OpenScholar in my domain:
http://scholar.web
Basically, when someone register for an account, his site URL is http://scholar.web/user, and his content will be at http://scholar.web/user/contents
I've been searching a way so that the URL is converted into: http://user.scholar.web/content for displaying his content via virtual subdomain (htaccess maybe)
Anyone can provide some solutions or guidance?
thanks
First of all, you'll need to change the DNS entry on the domain so that *.scholar.web points to your site.
Afterwards, (If you're using Apache) change the Apache vhost to accept *.scholar.web requests.
You can then use htaccess and/or PHP to do what you like with the URL formatting.
I used to have a domain called something along the lines of "iscool.com".
This is the method I used so I could use pseudo subdomains like "ben.iscool.com" and it would display content accordingly.
Related
I haven't found any solution to my problem with symfony and virtual hosts.
I have one website www.example.com and have routes that have different contents based on an id.
Example:
www.example.com/id/1 is one website with menus that point to subpages:
www.example.com/id/1/page1
www.example.com/id/1/page2
www.example.com/id/1/page3
what I want is to set a new domain that points to this website with id 1 and another domain that points to id 2, etc.
For example:
www.newdomain.com shows content from www.example/id/1
www.newdomain.com/page1 shows content from www.example/id/1/page1
www.newdomain.com/page2 shows content from www.example/id/1/page2
www.differentdomain.com shows content from www.example/id/2
www.differentdomain.com/page1 shows content from www.example/id/2/page1
...
First of all, you just have to point both virtual host configurations to the same folder to make both URLs work.
But the virtual host setting is just one side of the configuration. You won't be able to configure the actual behaviour of the application regarding the different incoming URLs. I don't know if this can also be achieved via .htaccess settings, but you can definitely check in the controller of your application from what URL the request was send and then forward the user accordingly.
A website example.com has one subdomain a.example.com. The point here is I want to redirect all existing and non existing subdomain (ex- b.example.com) to example.com without changing URL(URL MASK). To explain it more further, when a user enters b.example.com he must see example.com on his screen but URL must not change from b.example.com --> example.com. I think its possible from .htaccess file but I failed to achieve it.
Do I need to configure virtual host. Since I only have access to .htacces, I wish I can get it done
You need to have two things configured correctly:
A DNS entry with wildcard (*.example.com -> your server IP)
A virtual host with wildcard alias (ServerAlias *.example.com)
Then there is nothing to do in .htaccess. .htaccess alone can't do what you want. And please note also that this could be SEO-toxic (duplicate content), but it depends on your use case.
As you do not have access to virutal hosts config, may be you could go with subfolders instead of subdomains.
I have bought a domain and I want to redirect it to a directory on another subdomain.
Exemple:
A user type www.firstweb.com in the URL bar and he has to be redirected to www.secondweb.com/directory/ but the URL shown has to be www.firstweb.com without iframe.
Other exemple:
www.firstweb.com/contact/ shows the content of www.secondweb.com/directory/contact.php but the URL shown has to be www.firstweb.com/contact/ even after the redirect.
Both domain and servers are hosted by the same company (OVH).
I don't know if it is understandable but I dont know how to figure it out.
Thanks a lot for your help.
J.ROX
You can do this by installing NGINX (http://nginx.org/) on the webserver. Then you can check from which base URL the user is coming from, and return the appropriate content. This is also possible with an Apache server using Virtual Domain Names.
Or you can setup your DNS correctly, this can be done by your domain provider.
I have a domain example.com that has a folder in it example.com/folder/ that has another domain that points directly to it so example2.com points to example.com/folder/
When I access this via example.com/folder/ everything works fine and I can access my css and js folders which are a level below the folder in example.com/css/ and example.com/js/
When accessing from example2.com I don't see the css or js on the site and I get a 404 when trying to link directly to them by clicking the link in the view source output in firefox.
I should also mention that I have no problem with PHP includes that come from below the folder example2.com points to, just with the relative URLs referenced in the HTML.
Any idea how to get the site to let me access these folders below the root of example2.com from both example1.com/folder/ and example2.com?
I'm using a LAMP system. Also, my goal is to keep the system flexible enough that I can use it in multiple sets of domain/subdomain without having to edit server files or PHP.
EDIT - I "solved" this by adding a field in my db for the root domain all the subdomains will stem from and making static URLs for the linked js and css. This doesn't seem like the most elegant way to deal with it but it's the best I can think up right now. If anyone has any better let me know!
Just a guess, but sounds like <base href=> is needed.
In your case:
<base href="http://example1.com/folder/_">
That will make all relative URLs request resources from example1, even if users come visit on your example2.com vhost. Though all links will then also redirect people there. It affects both JS/IMGs and clicky things.
From what you have described you folder organisation looks like this:
/path/to/domain/folder/
/css/ ^
^ |
| domain2.com
domain.com
PHP on domain2.com won't have a problem accessing ../css because it operates on the server, but a browser can't go further back then /path/to/domain/folder/.
I would suggest to create a symbolic link (if possible) on the server:
ln -s /path/to/domain/css /path/to/domain/folder/css
Alternatively, you could use Alias in Apache to set up aliases for domain2.com/css to /path/to/domain/css/
Lastly, a <base> tag could help you (as mentioned by mario), but any links followed from a page with such a tag will switch back to `domain1``.
In order to keep the system as flexible as I wanted it I decided to put both the example1 url into the database and the folder name so I can construct absolute links to the files I need to access in the HTML page. This also seems necessary with my mod_rewrite, which changes tries to tack the locations of these files to the end of the "pretty URL" (like example2/post/2/css/main.css). Thanks for your ideas you steered me in the right direction!
2 of my urls, for example www.abc.com and www.def.com point to the same .php file. I have some text on that target page that needs to be dynamically changed depending on whether it came from www.abc.com or www.def.com. Can this be done? How?
See $_SERVER['HTTP_HOST'] for the host name of the current request.
In Apache's configuration, configure both hostnames to point to the same directory. If this is not possible, because you are on shared hosting for example, then you may still be able to use symlinks for both hostnames.
In PHP, you can determine the hostname that was used with the variable $_SERVER['HTTP_HOST'].