Erika Johansson
Erika Johansson

Reputation: 187

htaccess domain.com/sub to sub.domain.com

What I want: example.com/sub to be sub.example.com/ I created a subdomain and the host doesnt provide other help than an url to generate a htaccess file. It has 2 values "subdomain" and "folder".

In subdomain I wrote "https://example.com/sub" and in folder i wrote the foldername: "sub".

It gave me this that is not working for me. What am I doing wrong?

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} https://example\.com/sub
RewriteCond %{REQUEST_URI} !sub/
RewriteCond %{REQUEST_URI} !/.well-known/acme-challenge/
RewriteRule ^(.*)$ sub/$1 [L]

Upvotes: 1

Views: 31

Answers (1)

Amit Verma
Amit Verma

Reputation: 41219

You need to remove the url scheme from your %{HTTP_HOST} condition . and your RewriteCond %{HTTP_HOST} https://example\.com/sub condition should be RewriteCond %{HTTP_HOST} ^example\.com$ .

Try

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{REQUEST_URI} !sub/
RewriteCond %{REQUEST_URI} !/.well-known/acme-challenge/
RewriteRule ^(.*)$ /sub/$1 [L]

Let me know how it works for you.

Upvotes: 1

Related Questions