Help with rewrite rule for subdirectories
Hello,
I posted this under Security because people are able to access some directories I don't want them accessing, however, it might fit under a better topic, I just couldn't find one that seemed to match.
Anyway, I have manually set up sub-domains, like cpcalendars.mydomain.com, and whenever someone visits cpcalendars.mydomain.com, they get redirected to . This is good and what I want.
When someone visits mydomain.com/cpcalendars though, they see the contents of the cpcalendars directory. I don't want that. I want it so when someone visits mydomain.com/cpcalendars, they get redirected to
RewriteEngine on
# Allow .well-known through for Let's Encrypt.
RewriteCond %{REQUEST_URI} !^/\.well\-known/acme\-challenge/
# Redirect http requests to https because we have free SSL certs.
RewriteCond %{HTTP_HOST} ^cpcalendars.mydomain.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2080\/$1" [R=301,L]
# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php70 .php .phtml
# php -- END cPanel-generated handler, do not edit
Here's the contents of my /home//public_html/.htaccess file:
Any idea what I'm doing wrong and how to fix this? I do not want to enable the proxy subdomains. Thanks.
Here's the contents of my /home//public_html/.htaccess file:
# Tell the browser to check for index.html and index.php, in that order.
# if either exist, load that file by default.
DirectoryIndex index.php index.html
# Turn off caching for Google Chrome.
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate, post-check=0, pre-check=0"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
# Add P3P Privacy Headers to the site (this causes infinite redirects for some reason).
# Header set P3P "policyref="/w3c/p3p.xml""
#Turn RewriteMod on.
RewriteEngine On
# Redirect https://cpanel.mydomain.com to https://www.MyDomain.com:2083
RewriteCond %{HTTP_HOST} ^cpanel.mydomain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2083\/$1" [R=307,L]
# Redirect https://cpcalendars.mydomain.com to https://www.MyDomain.com:2080
RewriteCond %{HTTP_HOST} ^cpcalendars.mydomain.com$
# I thought this RewriteCond below would do the trick, but it doesn't.
RewriteCond %{HTTP_HOST} ^mydomain.com/cpcalendars$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2080\/$1" [R=307,L]
# Redirect https://cpcontacts.mydomain.com to https://www.MyDomain.com:2080
RewriteCond %{HTTP_HOST} ^cpcontacts.mydomain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2080\/$1" [R=307,L]
# Redirect https://webdisk.mydomain.com to https://www.MyDomain.com:2078
RewriteCond %{HTTP_HOST} ^webdisk.mydomain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2078\/$1" [R=307,L]
# Redirect https://webmail.mydomain.com to https://www.MyDomain.com:2096
RewriteCond %{HTTP_HOST} ^webmail.mydomain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2096\/$1" [R=307,L]
# Redirect https://whm.mydomain.com to https://www.MyDomain.com:2087
RewriteCond %{HTTP_HOST} ^whm.mydomain.com$
RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2087\/$1" [R=307,L]
# Redirect all other users to the https version of our website,
# because we have SSL certs now.
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=307,L]
# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php70 .php .phtml
# php -- END cPanel-generated handler, do not edit
Any idea what I'm doing wrong and how to fix this? I do not want to enable the proxy subdomains. Thanks.
-
I think I might have gotten it. This is what I added to the end of the Rewrite rules in the /home//public_html/cpcalendars/.htaccess file: RewriteCond %{REQUEST_URI} ^(.*)$ RewriteRule ^(.*)$ "https\:\/\/www\.MyDomain\.com\:2080\/$1" [R=301,L]0 -
Hello, I'm happy to see you were able to find a suitable rewrite rule. Thank you for updating this thread with the outcome. 0
Please sign in to leave a comment.
Comments
2 comments