1 minute to read - Apr 12, 2023

Generate .htaccess rewrite rules for redirects

Generate the .htaccess rewrite rules to 301-redirect any URL in a blog subdomain to a blog subdirectory within the same domain

To redirect all URLs in a blog subdomain to a blog subdirectory within the same domain, you can use the following .htaccess rewrite rules:

Copy code

`RewriteEngine on RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC] RewriteRule ^(.*)$ http://example.com/blog/$1 [L,R=301]`

This will redirect any URL in the `blog.example.com` subdomain to the corresponding URL in the `example.com/blog` subdirectory. The `R=301` flag indicates that this is a permanent redirect, and the `L` flag tells the server to stop processing rewrite rules.

Note that these rewrite rules assume that the `.htaccess` file is placed in the root directory of the `blog.example.com` subdomain. If the file is placed in a different location, you will need to adjust the `RewriteRule` pattern accordingly.

loading...