Apache2 Redirecting WWW to Naked Domain - wordpress

My apache2 virtual host file for example.com is as below. I'm using this with wordpress site.
I set up the site without bothering to redirect the naked domain to www. When I try and add any code to rewrite the URL it redirects back to the naked domain (301 redirect) and I'm in a redirect loop.
I can't figure out why my stack is redirecting www to naked domain. Any help appreciated. Standard LAMP stack with wordpress.
<VirtualHost *:80>
ServerName example.com
ServerAlias *.example.com
DocumentRoot /srv/www/example.com/public_html/
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
</VirtualHost>
Also my DNS is set up with an A NAME for www pointing to the server IP address.

Related

How to run different website in a same domain with HTTP and HTTPS

Can i run different websites in same domain. like
http://www.example.com ----> in WordPress
https://example.com/ -----> in laravel
Here is the reference site
Website : www.linqs.in
APP: https://linqs.in/username
App url will open user's profile by provided username.
sorry if i made mistake !! if this possible please guide me.
You can do this in your virtual host configuration:
Listen 80
Listen 443
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/path/to/wordpress"
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/path/to/laravel/public"
</VirtualHost>
You may also need to define directories if the sources are not under your default http root. For example:
<VirtualHost *:443>
ServerName example.com
DocumentRoot "/path/to/laravel"
<Directory /path/to/laravel>
AllowOverride All
</Directory>
</VirtualHost>
This will also allow Apache to serve that directory and use any .htaccess files (if it wasn't allowed already).
Since URL listen on port like http - port 80, https - port 443. So, you can ensure different website in a same domain via VirtualHost configure.

Apache reverse proxy and infinite loop

I have Server A and B. Server A hosts the main site www.example.com, Server B hosts another site using the subdomain test.example.com. On Server A I set up a reverse proxy, so that the Wordpress site running on test.example.com can be accessed via www.example.com/test
Now I want the subdomain test.example.com to be "invisible" for the user, so that a request to test.example.com will redirect to www.example.com/test.
Obviously, this got me into an infinite loop. I tried different things to break the loop to no avail.
Is there a way to do this?
<VirtualHost *:80>
ServerName test.example.com
RedirectMatch permanent ^/(.*) www.example.com/test
</VirtualHost>
Add the above apache conf and restart apache.

Redirect http xampp windows

I am running xampp on windows server and I want to redirect requests from my old url to the new one. I tried editing httpd-vhosts.conf with the following code
<VirtualHost *:80>
ServerName www.urla.gr
Redirect /www.urlb.gr
</VirtualHost>
and when I tried URLA from my browser it redirected me to URLB but URLB was not responsive. Both domain names have the same A record (the xampp server in question)

How to redirect a domain to different server's subdomain?

May this question or relevants asked before but I need to finish this issue properly. So let me explain what i want;
1- I've create and designed a wordpress project my own server subdomain ( eg: xyz.proje.com)
2- I've a domain (eg: www.xyz.com) which bought different company.
3- The project will remain my own server but the domain need to redirect this subdomain.
So how can i do this properly? How can change all xyz.proje.com ( and sub pages etc) links to www.xyz.com in this project?
Thanks.
Do you checked Create A Network in wordpress?
or Edit apache Virtual Host?
Listen 80
<VirtualHost *:80>
DocumentRoot /www/mainsite
ServerName www.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/subdomain1
ServerName subdomain1.example.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/subdomain2
ServerName subdomain2.example.org
# Other directives here
</VirtualHost>

Pointing domain name to server ip running XAMPP and wordpress

I installed XAMPP on my windows server and also installed Wordpress XAMPP module. I also bought a domain to point it to my server ip. Thing is , I want that when people enter mydomain.com , mydomain.com shows in the address bar and that it keeps showing while browsing.
First I tried to point the domain to my ip , and when I go to mydomain.com it shows mydomain.com/xampp
Then I tried to changing:DocumentRoot "C:\xampp\htdocs"
<Directory "C:\xampp\htdocs">
in httpd file in C:\xampp\apache\conf
to
DocumentRoot "C:\xampp\apps\wordpress\htdocs"
<Directory "C:\xampp\apps\wordpress\htdocs">
But this time when I enter mydomain.com it redirects to myipaddress.com/wordpress
All I want is:
1)When someone enters mydomain.com , he will see my wordpress home page.
2)Whenever a user is browsing mydomain.com , he will always see mydomain instead of myipaddress.
Any help would be appreciated.
Regards!
Type this at the bottom of your httpd file:
Alias /wordpress "C:/xampp/htdocs/wordpress/"
<Directory "C:/xampp/htdocs/wordpress/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Please take note that the directory that I stated above is a sample of a default directory. I am having a hard time trying to figure out your directory but the above example should make sense. After typing the codes on your httpd file, go to the directory of xamp/apache/conf/extra/ and openup the httpd-vhosts file. Type this at the bottom of the httpd-vhosts file:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.yourdomain.com
ServerAlias yourdomain.com
ServerAdmin email#yourdomain.com
DocumentRoot "C:\xampp\htdocs\wordpress"
</VirtualHost>
Double check your host file if you already entered this line:
127.0.0.1 yourdomain.com
Restart your Apache webserver. Hope this helps!

Resources