I'm going crazy with a Rewrite Rule on Apache.
Basically what I want to achieve is to rewrite any url like:
http[s]://www.example.com/something to
https://www.example.com I have a VHost on apache like the following:
<VirtualHost *:80> ServerName example.com ServerAlias example DocumentRoot /var/www/html/example_courtesy ServerAdmin [email protected] RedirectMatch 404 /\.git RedirectMatch 404 /\.svn <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/html/example_courtesy> Options Indexes FollowSymLinks MultiViews AllowOverride None Require all granted DirectoryIndex index.php indice.htm </Directory> RewriteEngine on RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerName example.com ServerAlias example DocumentRoot /var/www/html/example_courtesy ServerAdmin [email protected] RedirectMatch 404 /\.git RedirectMatch 404 /\.svn [...]
I tried deleting the [L] from the first rule and adding a rewrite rule like the following into *:443 VirtualHost:
 RewriteEngine on RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^.*$ https://%{SERVER_NAME} [L,R] What I receive is a rewrite loop, Firefox tells me "The page isn't redirecting properly".
I did many other tries with rewrite rules but no luck.
I only achieved to rewrite a specific URL like https://www.example.com/specific-path to https://www.example.com with a RedirectMatch, but this is not what I definitely want.
Any suggestions?
I searched here for a similar question but I didn't find a solution to my specific problem.