Need a help on .htaccess

I want to do 3 things:

  1. My website URL will always start with https:// and without www (ie. https://example.com/) no matter if it is typed with or without .

  2. if someone types example.com/artist/abc/xyz.etc then it will become artist.example.com/abc/xyz.etc

  3. if someone types example.com/help/abc/xyz.etc then it will become help.example.com/abc/xyz.etc .

  4. and no 3. will happen only for artist and help subdomain, not for others (such as example.com/img/ will not become img.example.com/)

I need full .htaccess code . I have no idea on .htaccess . can someone kindly do that for me? (The whole code plz, which I can copy paste). I believe it will be a few sentence but this will help me a lot . Thanks in advance.

Hello there,

Try these:
1.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

For 2, 3 and 4:

Redirect 301 /old-dir
https://subdomain.example.com/new-dir

You may also try this if the above code doesn’t work:

RedirectMatch 301 ^/old-dir/$ https://example.com/new-dir/

While I’m not sure for 2, 3 and 4 but it’s worth a try. It’s up to you to make sure that the code will have the correct informations you want.

Hi!
Should I separate these codes with a comma? or just simply type them one after another?

Bro, another question, will it take some time to effect? or will effect immediately?

I wanted this to happen only when the link is
exm.com/artist/abc => artist.exm.com/abc
and for exm.com/help/abc => help.exm.com/abc
not for all links. if the link is
exm.com/img/abc , it will remain same as exm.com/artist/abc, no change.
I have 2 subdomain, which will be redirected but not for other cases.

One after another will be fine just make sure to leave a space.

It will take effect immediately just make sure to clear your browser cache.

That’s absolutely hard for me, I’m not that of an expert with .htaccess as well but you may try to search some documentations, blog and etc. online to find what you are looking for.

1 Like

Thank you brother. Have a nice day! <3

I want exactly opposite to this question.

Still thanks a lot.

Found an answer .htaccess - Redirect directory to a subdomain - Stack Overflow . But here is a small difference,
They taught how to make
http://codigofacilito.com/video/W53XHWkbz34
into
http://videos.codigofacilito.com/video/W53XHWkbz34
but I want
http://videos.codigofacilito.com/W53XHWkbz34.
Please check it once more, I really appreciate your help brother

As far as what I understand is when you insert this code:

RewriteRule ^(video/.*)$ http://videos.example.com/$1 [R=301,L,NC]

Is that every files in that subdirectory will permanenently moved/redirect to http://videos.example.com/.

As far as what I understand with that rule, this is what I think would happen:
Example 1:

http://example.com/random123/ will permanently redirect to http://videos.example.com/random123/

Example 2:

http://example.com/12345/ will permanently redirect to http://videos.example.com/12345/

Example 3:

http://example.com/abcde/ will permanently redirect to http://videos.example.com/abcde/

And this is what you would also like right?
If so then that htaccess rule is what you just need.

1 Like

Problem solved. Thank you brother. Have a nice day! <3 I really appreciate your help.

Redirection from subdir to subdomain – for All URLs
From – http://www.demo.com/mydir/{article-url}
To – http://subdom.demo.com/{article-url}

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.demo.com
RewriteRule ^mydir/(.*)$ http://subdom.sample.com/$1 [L,R=301]

Best of luck and keep doing good works and stay safe during corona virus <3

1 Like

You’re welcome and stay safe as well :slight_smile:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.