I have two subdomains private
, public
(but public
is only alias of private
) and one main domain www
. I need to redirect all URLs from public
subdomain to www
, except existing PDF files and one URL address. I have these rules which work fine, but I can not add the exception for the one certain URL.
e.g.:
public.example.com
=>www.example.com
// OKpublic.example.com/any-existing-file.pdf
=> stays atpublic.example.com/any-existing-file.pdf
// OKpublic.example.com/any-not-existing-file.pdf
=>www.example.com
// OKpublic.example.com/anything-except-certain-url-below
=>www.example.com
// OKpublic.example.com/certain-url
=> need to stay atpublic.example.com/certain-url
, but it is redirected atwww.example.com
// KO
I have these rules in my .htaccess
file.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^public\.example\.com$
RewriteRule ^$ http://www.example.com/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^private\.example\.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !\.[[:alnum:]]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R=301,QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)/?$ ?page=$1 [QSA,L]