0

I have two ec2 servers in which one is running my website and another is blog with sub-domain. Both are having apache2 installed.

How can i redirect http://www.example.com/blog to blog.example.com ?

1 Answers1

1

You can use mod_rewrite.

Create .htaccess file in root containing

RewriteEngine On 
RedirectMatch 301 ^/blog http://blog.example.com/
Vasia Dunaev
  • 149
  • 1
  • 10
  • hope it helps - https://stackoverflow.com/questions/11715684/htaccess-redirect-folder-to-a-url – Vasia Dunaev Aug 19 '17 at 06:17
  • not working. Not Found The requested URL /blog was not found on this server.. Getting this error while trying to access `example.com/blog` – gurupal singh Aug 19 '17 at 06:24
  • 1) Do you have installed mod_rewrite? 2) In which folder did you put this file? – Vasia Dunaev Aug 19 '17 at 06:31
  • yes mod_rewrite is enabled. I put .htaccess in root folder of my website and my blog is running on another server with `blog.dvele.com` sub-domain . I want users to redirect from `example.com/blog` to `blog.exmaple.com` – gurupal singh Aug 19 '17 at 06:34
  • .htaccess should be in the same folder as index.html. – Vasia Dunaev Aug 19 '17 at 06:41
  • yes .htaccess is in the same folder as index.html but still getting `Not Found The requested URL /blog was not found on this server` error – gurupal singh Aug 19 '17 at 06:56
  • it looks like mod_rewrite is not working. Please check that options "AllowOverride All" in your apache virtual hosts file. And you restart apache after enabled mod_rewrite. – Vasia Dunaev Aug 19 '17 at 07:12