RewriteRule ^/$ /template.php
Assuming this directive is in a server or virtualhost context (ie. not a directory or .htaccess
context), then this will only match requests for the document root (ie. /
) and ignore /blabla
and /lalala
.
To match <anything>
, except index.php
(or an empty URL-path, assuming index.php
is set as the DirectoryIndex) then do something like the following instead:
RewriteRule ^/(index\.php|template\.php)?$ - [L]
RewriteRule ^ /template.php [L]
The first rule stops any further processing if /
or /index.php
or /template.php
is requested, which allows your main site (ie. index.php
) to be accessed and prevents a rewrite loop.
The second rule rewrites all other URLs (whether they map directly to filesystem resources or not) to /template.php
.
It's unusual that you wouldn't want static resources (images, CSS, JS, etc.) to be excluded from this rewrite, but you've confirmed this in comments.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Since you are in the main server config (ie. not .htaccess
) then you shouldn't be using mod_rewrite to issue the HTTP to HTTPS redirect anyway. You should have a simple mod_alias Redirect
in the non-canonical <VirtualHost *:80>
container.
Doesnt the https part mess up the URN part?
No. (To answer this specific question - if you were using mod_rewrite.)
This is of course assuming you have the directives in the correct order. The external redirect from HTTP to HTTPS should appear first.