Search code examples
wordpress.htaccesshttp-redirecthttp-status-code-301cloudflare

Why I can't redirect subdomain from htaccess while having Cloudflare?


Why I can't redirect subdomain from htaccess while using CloudFlare SSL?

PS I don't know if I can paste URL here so I won't paste it to avoid removal of the question.

I'm getting this problem in Chrome (but it doesn't work in Firefox either)

error

I know there are fixes on the internet for this error but none worked for me. Is it because I have root domain connected to CloudFlare (also affects subdomains)?

What I did is: 1. created a subdomain in hosting and set its file directory. 2. in that file directory made .htaccess file. 3. inside the file

Redirect 301 / https://rootdomain/firstfolder

but it falls into redirects loop :(


Solution

  • With my .htaccess code, I check if the domain has the www. dub on the domain, then I redirect it to the subdomain without the www. dub on it. Also, because I don't think you want to change it, I place a 301 Redirect on it also.

    I forgot to mention, usually people do not use the www. on the subdomain also, so I am guessing that you don't want people to use it either.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.domain\.com$
    RewriteRule ^/?$ "http\:\/\/sundomain\.domain\.com\/" [R=301,L]
    

    For specific url : put below code in your subdomain.domain.com's .htacess

    Redirect 301 /blue-car/ http://www.example.com/cars/red-car