0

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 )

000-default-le-ssl.conf

<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>
</IfModule>

000-default.conf

<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]
</VirtualHost>

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

Thanks a lot!

indianwebdevil
  • 220
  • 1
  • 6

1 Answers1

1
<VirtualHost example.tld:443>
   ServerName example.tld
   Redirect permanent / https://example.tld/abc

https://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirect :

Then any request beginning with URL-path will return a redirect request to the client at the location of the target URL. Additional path information beyond the matched URL-path will be appended to the target URL.

By using "/" as the URL-path and "/abc" target URL /abc will also be matched and get redirected to /abc/abc.

What you probably want is to only match the bare domain and redirect that to /abc, right?

Use a RedirectMatch instead:

RedirectMatch permanent ^/$ https://domain.tld/abc
HBruijn
  • 77,029
  • 24
  • 135
  • 201