Add www when accessing root domain, not using htaccess file - apache

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

Related

Apache Alias Infinite Redirect

I've been having a lot of trouble with setting up an Alias for my Virtualhost.
I have 2 different codebases that need to be on the same server, I have the admin app as well as the client app.
My virtual host is as follows :
<VirtualHost *:80>
DocumentRoot "E:/xampp/htdocs/site/client"
ServerName local.site.com
Alias /admin/ E:/xampp/htdocs/site/admin/
</VirtualHost>
My folder structure is as follows :
site
- admin
- client
Everything works fine as far as the client goes, I can hit everything under the subdirectory.
The issue arises when I try to hit local.site.com/admin. It redirects the URL to local.site.com/admin/index.php/index.php... and so on (there is like 10 of them).
I also can not hit the index.html in the admin folder directly.
The result I expect is for all traffic to /admin to be directed to the admin folder.
I can not for the life of me figure out why the redirect is happening.
I do not have any .htaccess files in the folders for what its worth.
Any help would be appreciated.
Thanks

Apache Redirect domain.com/dir/slug to sub.domain.com/dir/slug silently without .htaccess

I'm having the darndest time trying to figure this out.
I have a site on a legacy system which will not permit me to alter the .htaccess file at domain.com. I have moved part of this site to a WordPress install located at sub.domain.com. I have to make the URL domain.com/dir/ redirect silently to sub.domain.com/dir/. How can I go about this? I can edit the Apache config files for both domain.com and sub.domain.com, and the .htaccess for sub.domain.com, but not the .htaccess for domain.com
Thanks!
Just add the redirect into the apache config files. In the virtualhost for domain.com:
Redirect 301 / http://sub.domain.com/
If by "silently" (not sure what that's supposed to mean since redirects are involve the browser sending a new request), I'm guessing you want to reverse proxy? Then you'd need to make sure mod_proxy is loaded, then do:
ProxyPass / http://sub.domain.com/

Apache Mod-rewrite across domains?

OK, I have a site, at www.domain.com. I added a web app on heroku and it has it Heroku URL and a custom domain. However, what I'd like to do is have it accessible via those two URL but on the www.domain.com site, I'd like to access that new server via www.domain.com/customapp. I figured I could do it through URL rewrite. But all the examples I see are doing the the other way, so is my idea possible? Is mod-rewrite the way to go?
Thanks.
Why don't you try setting up a reverse proxy for www.domain.com? Assuming you are using Apache 2.2, it's pretty easy to do if you have access to the httpd.conf or httpd-vhosts.conf file.
In your case I would add the following to your httpd.conf or httpd-vhosts.conf file.
ProxyRequests Off
ProxyPass /customapp/ <URL-to-Heroku-App>
ProxyPassReverse /customapp/ <URL-to-Heroku-App>
For more information, see the docs.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypassreverse

help regarding setting up pseudo/fake subdomains on apache

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.

Magic Apache redirecting for /~username

I have inherited a webserver already serving some websites. I am trying to migrate some of those sites to a new webserver.
One of those websites has a page called:
http://mydomain/ABCDepartment/
This URL also works:
http://mydomain/~joesmith
and the index page for joesmith actually lives in /var/www.../ABCDepartment/people/joesmith/
Now I am checking in httpd.conf and I see the following:
UseCanonicalName Off
UserDir public_html
UserDir disabled root
There are no special mod_rewrite rules for joesmith or the ~
How is this magic happening? UseCanonicalName is off, and if it wasn't UserDir public_html should look in /home/joesmith/public_html
What am I missing?
This is an Apache extension called userdir: http://httpd.apache.org/docs/1.3/mod/mod_userdir.html
It automatically rewrites requests to point to a folder called public_html within the user's home directory (the web server must have read access up the tree to this folder).