Multiple redirects with 301 apache from https://domain.tld to https://domain.tld/subdir/

by indianwebdevil   Last Updated June 12, 2019 08:00 AM

I have the current setup with Apache2, lets encrypt to move

http://domain.tld => https://domain.tld
http://www.domain.tld => https://www.domain.tld

Its working perfect,

Now I wanted move all my domainname visit to a subdir

http://domain.tld => https://domain.tld/subdir ( Done! its working )

But when I tried to redirect https domainName visit to subdir, I get multiple redirects.

https://domain.tld => https://domain.tld/subdir ( Endless redirect to 
https://domain.tld/subdir/subdir/subdir/ and so on )


<IfModule mod_ssl.c>
<VirtualHost domain.tld:443>
   ServerName domain.tld
   ServerAlias www.domain.tld

   DocumentRoot /var/www/domain.tld/html
   Redirect permanent / https://domain.tld/abc

   SSLCertificateFile /etc/letsencrypt/live/domain.tld/cert.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/domain.tld/privkey.pem
   Include /etc/letsencrypt/options-ssl-apache.conf
   SSLCertificateChainFile /etc/letsencrypt/live/domain.tld/chain.pem



<VirtualHost domain.tld:80>
   ServerName domain.tld
   ServerAlias www.domain.tld

   DocumentRoot /var/www/domain.tld/html

   # This works like a charm !( DONE! )
   Redirect 301 / https://domain.tld/roll-out/

# RewriteEngine on
# RewriteCond %{SERVER_NAME} =domain.tld [OR]
# RewriteCond %{SERVER_NAME} =www.domain.tld
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

I have commented the last 3 lines, Please help me understand why this happens and whats the solution.

Thanks a lot!

Related Questions

apache2 mod_rewrite redirect without http body

Updated April 04, 2018 19:00 PM

.htaccess 301 redirect remove [] from the URL

Updated August 13, 2018 15:00 PM

Apache Rewrite not working

Updated September 22, 2018 18:00 PM

URL without "http://" does not work in Apache

Updated August 10, 2017 20:00 PM