• Resolved Vivek Athalye

    (@vnathalye)


    I’m trying to redirect urls such as https://type1.myprods.com to https://myprods.com/category/type1.
    There is an exception though: https://demo.myprods.com (or anything lik https://type1.demo.myprods.com) should not get redirected, because there is a separate dummy site in place for giving demo of the main site.
    I’ve checked the add_rewrite_rule documentation and used it for handling other custom permalinks and they are working fine. But not able to understand how I can use it to handle subdomains.

    Or do I need to handle it with .htaccess?

    Any help is appreciated

    (I was not sure if this question should be posted to Developing with WordPress forum, hence posting it here)

Viewing 5 replies - 1 through 5 (of 5 total)
  • If all your subdomains are pointing to same code source, then it is better to handle it with .htaccess

    Moderator Support Moderator

    (@moderator)

    (I was not sure if this question should be posted to Developing with WordPress forum, hence posting it here)

    It’s not Developing or Everything else WordPress. It’s Fixing WordPress and that is where I moved your topic.

    Thread Starter Vivek Athalye

    (@vnathalye)

    Thanks @moderator

    @ddsuresh , I’ve put following rewrite rules in .htaccess. But it’s not working as per my requirement.


    RewriteCond %{HTTP_HOST} ^(.+\.)?demo\.myprods\.com
    RewriteRule . - [L]

    RewriteCond %{HTTP_HOST} !^myprods\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(.+)\.myprods\.com [NC]
    RewriteRule . https://myprods.com/category/%1 [R,L]

    The idea here is that, the first rule will ignore anything that points to demo site and let it get processed by the separate site hosted at demo.myprods.com.

    The second rule is supposed to capture the subsite name and pass it to the redirect URL. But when I access https://type1.myprods.com, the URL doesn’t change and I get the “site can’t be reached” error.

    I’m not able to figure out what’s wrong here. Any help?

    Thread Starter Vivek Athalye

    (@vnathalye)

    @ddsuresh my bad … I had forgotten to add DNS entry for subdomains 🙁 … after adding CNAME entry for *.myprods.com to point to myprods.com “site can’t be reached” error is gone.

    But now when I access https://type1.myprods.com, instead of showing my website, its showing me my webhost’s custom home page. I tried commenting my changes in .htaccess and still getting same behavior (webhost’s custom home page). which makes me think that the rewrite rule is not getting applied / .htaccess is not getting into picture at all.

    Is that correct understanding?
    Anyway I’ve raised a support ticket at my webhost. Hopefully will get a solution soon.

    Thread Starter Vivek Athalye

    (@vnathalye)

    For those who come across similar issue …

    My webhost admin asked me to create wildcard subdomain using cPanel.

    So I first removed the CNAME entry I had added manually. Then created wildcard subdomain from cPanel. Just to make it easier to handle, I created separate document root to handle all subdomain requests. In this folder I added .htaccess that is supposed to redirect user to main site.
    Also added index.php to understand if my .htaccess is getting applied or not.

    Initially this index.php was getting displayed. After some more testing I realized that the rewrite rule should have been like:

    RewriteRule .? https://myprods.com/category/%1 [R,L]

    The ? was missing and hence it was not getting applied, effectively showing my index.php.

    After updating this rewrite rule, all subdomains / URLs like https://type1.myprods.com are correctly getting redirected to https://myprods.com/category/type1, while keeping the demo site working separately.

Viewing 5 replies - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.