I have this site that needs to be inside our secure network that my work uses. I would like to redirect the users when they are trying to access the page to this secure path. For example, If someone tries to access mydomain.com/pictures I want apache to take them to https://mycompanysecure.com/,ThisSite=mydomain.com/pictures,SSL. I want the whole entire site to be redirected like the example above. I think I need to use wildcards, but I am really new on Apache and I don't know how to do this. I want also want also to make it the default when my app launches it always stay like that. So far I was only able to do this with the root path.
This is what I have so far:
<VirtualHost *:80>
ServerName mydomain.com
redirect / https://yourcompany.net/,ThisSite=mydomain.com,SSL
</VirtualHost *:80>
You can capture and substitute the URL by using RedirectMatch:
RedirectMatch ^/(.*) https://yourcompany.net/,ThisSite=mydomain.com/$1,SSL
Related
I have found many suggestions around the net on this, but nothing that matches my exact issue. I have a webserver setup, that I have had our networking guys give me a DNS name for. Let's call it analytics.mycompany.com. This runs on port 80 and I have not issues.
A few months back I created an RStudio Shiny app that, by default, runs on port 3838. Therefore, I get to this via http://analytics.mycompany.com:3838/dashboard/. Which is all good and fine, but leadership has asked for an easier URL. I had my DNS guys give me an alias to the analytics.mycompany.com as dashboard.mycompany.com. Which, by default just points to the same port 80 website.
Now, I figure with a little apache/virtualhost/rewriterules/proxy I can tell apache to handle anything it receives from the dashboard.mycompany.com to just display the dashboard at http://analytics.mycompany.com:3838/dashboard/. After playing with this, I can get a URL like http://analytics.mycompany.com/dashboard/ to forward to the correct :3838 port and URL, but what I really want is for someone to be able to just enter http://dashboard.mycompany.com and just have the shiny dashboard appear. I know in DNS you cannot make aliases to ports, so that is out. I was hoping apache could handle this in some way, by saying, "ok, I have this URL on port 80 and I'm going to just display the content of this other site at port 3838."
I'm not sure if this is possible, but it is what I'd like. Right now my httpd.conf file for the virtual host at port 80 is as such:
<VirtualHost *:80>
ServerAdmin admin#mycompany.com
DocumentRoot /var/www/html
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^HEAD
RewriteRule ^/dashboard(.*) /foo/index.html
Redirect /dashboard http://analytics.mycompany.com:3838/dashboard
ProxyPass /dashboard/ http://analytics.mycompany.com:3838/dashboard
ProxyPassReverse /dashboard http://analytics.mycompany.com:3838/dashboard
</VirtualHost>
This was based on an example I found and is as close as I've come. I am thinking that I need some sort of virtual host for the new alias that might look like:
<VirtualHost dashboard.mycompany.com:80>
.....
</VirtualHost>
However, all the examples I find of VirtualHost is either *:80 or some IP addres like 192.168.0.1:80 or the like. If anyone has a suggestion or a way I can server this up at a simple URL, I would greatly appreciate it. Thank you so much!
To bring this to a close, this was a two part process:
I had to disable SELinux as it was interfering.
I created a VirtualHost entry as specified above (basically a port redirect)
Since we use a primary DNS, I had to have my network folks add an entry to InfoBlox for the domain.
After that, everything was working as expected. :)
I have an apache server with some websites built in Wordpress, using vhosts.
The thing is that I have for all of them a configuration like:
ServerName site1.com
ServerAlias www.site1.com
When I access to Site1 through "site1.com" the URL changes to "www.site1.com". The same for Site2, Site3, etc. But for SiteN it's inverse. If I access to "siten.com" it keeps the URL and if you go to "www.siten.com" it changes to "siten.com".
I know I can change this using htaccess file, but my doubt is why some sites has a default and the new site has another default? All the htaccess have the same things and the vhost configuration is the same for all.
Thank you,
Done! The change should be implemented in Wordpress configuration, is not a htaccess issue
I run a couple dozen sites on my test VPS, and currently use mod_vhost_alias to avoid needing a new VirtualHost every time I throw up a new site. My current configuration looks like this:
<VirtualHost *:80>
ServerName my.servername.com
ServerAlias *
VirtualDocumentRoot /var/www/%0/public_html
</VirtualHost>
Inside my /var/www directory, each site has its own directory. For instance, the path to my personal page is /var/www/personalsite.com/public_html/index.php. This is working great for requests to http://personalsite.com.
However, this does not work when requests come in for http://www.personalsite.com. For some of my other sites, I have the inverse problem -- the directory may be /var/www/www.sitename.com/public_html, so requests for http://www.sitename.com are fine. However, requests for http://sitename.com do not work.
Is there a way to set up my Apache config so that when a request comes in, it does the following? Are there any performance implications of doing it this way?
In pseudocode:
1. Check if the directory or file exists. If it does, skip the rest of the rules
(but don't stop, in case a local .htaccess has rules in it for pretty URLs
in WordPress or Concrete5)
2. If the file/directory does not exist:
1. If the host header starts with "www":
1. remove the www from the host header and try the first rule again.
2. If the host header does not start with "www":
1. add "www" to the beginning of the host header and try the first rule again
3. If it still fails after trying both conditions:
1. Go to a 404 error page
I'm currently doing this with about 20 virtualhosts, but that seems ridiculous when I have to add a new one for each site. The point of using mod_vhost_alias was to avoid needing all these VirtualHosts in the first place.
Assuming you're OK with redirecting users, you can use one of the techniques from https://stackoverflow.com/a/2361508/881615:
either set a mod_rewrite rule to remove the leading www. from requests,
or set a redirect in each vhost to redirect requests with a leading www. to the top-level domain
First of all, sorry if I got the term 'pseudo subdomain' wrong.
what I am trying to achieve is this-
When someone registers on my application, they get a new url like..
yourname.myapp.tld
I dont want to use the subdomain system for this. To be frank, I dont know how the subdomains exactly work but it guess it requires a folder per subdomain inside the document root and then the server redirects the requests there.
Can this be achieved by doing something like -
when a visiter types any subdomain, (anything.myapp.tld), he is able to access myapp . In the index.php file i will explode the $_SERVER['HTTP_HOST'] to get the subdomain which i will store in session and will thereafter act as an identifier for that user. Ideally i wouldnt want to create any vhosts or add many lines to the hosts file. Can this be achieved with just one vhost?
Is this possible with mod rewrite or something ?
Yes you can archive this using wildcard that needs to be configured on both, the dns server and http server
On the dns a entry like this (installing dns on ubuntu https://help.ubuntu.com/10.04/serverguide/C/dns.html):
; wildcard subdomains are all directed to this IP
; of course this should be the IP of your web server
*.domain.tld. IN A 1.2.3.4
At apache an entry like this:
<VirtualHost 111.22.33.55>
DocumentRoot /www/subdomain
ServerName www.domain.tld
ServerAlias *.domain.tld
</VirtualHost>
What happens after is that everything.domain.tld will be going to your main folder so you can use the index.php to redirect it to the right place or even an htaccess using mod_rewrite.
I have a site at blog.foobar.com that I have closed down, and I want any
page requested there to be forwarded to www.foobar.com
I want my VirtualHost config to do this for me. I currently have the following lines that does nearly what I want but not exactly:
redirect permanent / http://www.foobar.com
Unfortunately what happens is that if I ask for blog.foobar.com instead of forwarding to www.foobar.com it serves the pages on blog.foobar.com instead.
Is there a way doing this in the VirtualHost config or should I use a .htaccess file instead?
Regards
Steve
You can use the Redirect directive in the context of either a VirtualHost or a .htaccess file. However, what you probably want is a RedirectMatch:
RedirectMatch permanent (.*)$ http://www.foobar.com$1
With that inside your blog.foobar.com VirtualHost, any request to blog.foobar.com would be directed to the same page on www.foobar.com, ie. blog.foobar.com/my/page would go to www.foobar.com/my/page.