How to rewrite a subdomain with .htaccess?

by kyleigh.wolff , in category: SEO , 8 months ago

How to rewrite a subdomain with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by priscilla.langworth , 8 months ago


To rewrite a subdomain using .htaccess, you can use the following steps:

  1. Confirm that you have enabled the mod_rewrite module in your Apache server. You can do this by checking if the following line is uncommented in your server configuration file or virtual host file: LoadModule rewrite_module modules/
  2. Create or modify the .htaccess file in the root directory of your subdomain.
  3. Add the following code to the .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

Replace "" with your actual subdomain, and "" with the URL of your desired destination.

  1. Save the .htaccess file and upload it to the root directory of your subdomain.
  2. Test the rewritten subdomain URL in your browser to confirm that it is redirecting correctly.

Note: The above code uses a 301 redirect (permanent redirect) to the specified URL. If you want to use a different redirection method, you can modify the [R=301,L] part accordingly.