Amazon EC2 + 301 www redirection - apache

I'm running a site on AmazonEC2 instance, and so far everything is ok, except a single glitch. When I navigate to
www.mysite.com/somepage.html
, browser happily opens the desired page. But when I try
mysite.com/somepage.html
, I go to the root of my site, i.e. to
www.mysite.com
LiveHTTPHeaders tells me that 301 redirection occurs. So here's the question: what configuration files do I need to change to make redirection respect URL path?
Also, I noticed that nginx does the redirection. Does it mean that redirection is happening outside of EC2 instance or not?
Thank you in advance.

You should have some kind of settings that is redirecting your request from http://mysite.com/ to http://www.mysite.com/
Following is kind of conf. settings you should find in your nginx.conf or inside /etc/nginx/sites-enabled/<site-vhost-name>
server {
server_name example.com;
rewrite ^/(.*) http://www.example.com/$1 permanent;
}
This tells NGINX to redirect request from http://mysite.com/ to http://www.mysite.com/.
If yes?, then blindly remove those two lines of conf.

Related

Apache mod_rewrite

I'm using Liferay 6.2 EE that runs on tomcat but it's fronted by an Apache server. I want to redirect users so that whenever they hit the old liferay URL, it redirects them to the new liferay URL. I changed the URL in liferay, so it is now the new URL. However, whenever I try to go to the old URL, I get a page request error. It never redirects me to the new URL. In /san/apache/conf/ I put my redirect code inside of httpd.conf. This my code:
RewriteEngine On
RewriteRule ^group/old/(.*) /group/new/$1 [L]
After I applied these changes, I restarted the Apache server and it still doesn't work. I've tried a bunch of other combinations as well. Does anyone know what I'm doing wrong? Is there some place else I have to make this change?
Ah, since your rewrite rule is lying in the server config file (instead of htaccess file), the mod-rewrite receives URLs with the leading slashes (/). So, the rule should be:
RewriteEngine On
RewriteRule ^/group/old/(.*) /group/new/$1 [L]

Drupal Domain Redirection

We have two domains: www.example.com and www.example.org. Both point to the same site. But, we'd like everything to point to .org. We are running Drupal on a LAMP server hosted by Media Temple.
We have now started to have problems because our .com SSL cert expired, so anybody who goes to the .com site routinely gets scary messages in Chrome, etc.
How can we make it so that if somebody goes to https://www.example.com in google, they get nicely directed to http://www.example.org?
You can do this multiple ways.
.htaccess
RewriteEngine On
Redirect 301 / https://www.exmaple.org
In a PHP file
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.example.org");
header("Connection: close");
You can try this module :
https://www.drupal.org/project/domain_301_redirect
This is the domain that all other domains that point to this site will be 301 redirected to. This value should also include the scheme (http or https)
I Hope help you!

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/

mod_rewrite Cannot redirect without rewriting url

I'm trying to redirect to another server application running on a different port of the same box with apache HTTPD as the frontend server running on port 80. I'm using the rewrite engine and the following syntax to redirect calls:
RewriteRule ^/?products/(.*)$ http://www.example.com:9000/$1 [L]
This works great, but the url changes to port 9000 in the browser. Whenever I change the [L] to a [P] for proxy I get a 404, not found error in the browser.
How do I fix this so that the url doesn't change in the browser, but that it still works?
You need to make sure you have mod_proxy loaded, otherwise the P flag won't work.
You can also use the ProxyPass directive as part of mod_proxy in your vhost config.

Apache: Redirect blog.foobar.com to www.foobar.com

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.