skip to Main Content

How do I rewrite:

subdomain.example.com/page to example.com/subdomain/page?

I’ve tried redirecting in my cPanel and changing the site URL in wp_options. Still no luck.
Thanks in advance.

2

Answers


  1. Use the following htaccess code for this purpose.

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC]
    RewriteRule ^(.*)$ "http://example.com/$1" [R=301,L]
    </IfModule>
    
    Login or Signup to reply.
  2. Try

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^(.*).example.com$ [NC]
    RewriteRule ^(.*)$ "http://example.com/%1/$1" [QSA,L]
    </IfModule>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search