skip to Main Content

I’m trying to redirect a site with the following url structure:

https://example.com/2021/about
to
https://2021.example.com/#about

https://example.com/2021/visit
to
https://2021.example.com/#visit

how can i do this?

i tried adding this to the /about directory in the original domain:

RewriteEngine on
RewriteBase /
RewriteRule (.*)  https://2021.example.com/#about [R=301,NE, L]

but what i got after the redirect was
https://2021.example.com/#about2021/about

which is not right. any help is appreciated

[EDIT] i only want to apply this to some folders, like /2021/about and 2021/visit

2

Answers


  1. Could you please try following, written based on your shown samples. Please make sure to clear your browser cache before testing your URLs. Following will only be applied to 2021/about OR 2021/visit uris.

    RewriteEngine ON
    RewriteCond %{HTTP_HOST} (example.com) [NC]
    RewriteRule ^(2021)/(about|visit)/?$ http://$1.%1/#$2 [R=301,NC,NE,L]
    
    Login or Signup to reply.
  2. You may use this redirect rule:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^(?:www.)?(example.com) [NC]
    RewriteRule ^(20d{2})/(.+?)/?$ https://$1.%1/#$2 [R=301,L,NE]
    

    Make sure this is your topmost rule in .htaccess and you clear your browser cache before testing this new rule.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search