Reputation: 981
I have a example.com and i created a subdomain for it in Cpanel. In Cpanel it appears:
test.domain.com /public_html/test not redirected I want to access my new subdomain: test.domain.com I have created an index.html in the subdomain folder: /home/domainname/public_html/test
My .htaccess is:
AddType text/x-component .htc
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RedirectMatch 301 ^/test/(.*)$ http://test.example.com/$1
RewriteRule ^(en|fr)/([a-z]*) /index.php
RewriteRule !\.
(js|ico|gif|jpg|jpeg|png|css|swf|htm|xml|php|map|ttf|woff|woff2)$
index.php
RewriteRule ^(form|ajax|captcha)/([a-z]*) /index.php
The domain.com have ssl and for subdomain i don`t. I added this line in .htaccess for subdomain:
RedirectMatch 301 ^/test/(.*)$ http://test.example.com/$1
But not working: when accessing the test.example.com i get "This page isn’t working test.example.com redirected you too many times."
and if using with https:
RedirectMatch 301 ^/test/(.*)$ https://test.example.com/$1
I get of course a ssl warning and Not Found The requested URL /home/domainname/public_html/index.php was not found on this server.
What i have done wrong?
Upvotes: 0
Views: 7969
Reputation: 5129
You should add RewriteBase
directive:
RewriteEngine on
RewriteBase /
You should also update the RedirectMatch
directive to:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^test/(.*)$ http://test.example.com/$1 [R=301,L]
It tests if the request domain is example.com
, and if request URI prefix is test/{any_characters}
, redirect to test.example.com/{any_characters}
permanently.
Upvotes: 4