my htaccess for the sub domain is not working in wordpress

I have a subdomain imonline on the domain www.techchef.co

I have already created subdomain in cpanel which is pointing to this folder. so the url should be imonline.techchef.co

Read More

i have tried wordpress provided .htacess for sub domain mentioned below but does not works, i have also tried some other configs too but it does not work even too.

Please guide me what i am missing in .htacess file

My Current htacess

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*.php)$ $1 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

before that i was writing below one

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ http://imonline.techchef.co/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /imonline/index.php [L]
</IfModule>
# END WordPress

Related posts

Leave a Reply

1 comment

  1. Regarding our little comment conversation:

    The mistakes

    You lost me.

    There are a lot of things wrong with your .htaccess. But I don’t blame you. I believe everybody had a hard time getting along with mod_rewrite in the beginning… I even struggle sometimes even today. 😉

    1. You have too many [L] flags. What do you think they do? The L stands for last. [L] terminates the routing routine. All subsequent directives are ignored.

    2. You don’t use a RewriteCond %{HTTP_HOST} ^subdomain.domain.tld$ followed by an appropriate RewriteRule.

    3. Your previous attempt would redirect every request to the subdomain and simply end there due to the [L] flag.

    4. Even worse, you’ve used a [R=301] (moved permanently) during testing!! If any of your visitors visited your website in the meanwhile, their experience of your website may be broken forever! That is until they clean their browser cache.

    5. RewriteRule ^wp-admin$ wp-admin/ [R=301,L] should redirect everything within the wp-admin directory to the wp-admin/index.php file, which isn’t necessarily what you want. wp-admin/edit/article would also be routed to wp-admin/.

    That about sums up all your mistakes I’ve noticed. Now let’s go about redirecting your subdomain… I haven’t tested this since my machine currently isn’t set up for testing, so you might have to do some debugging. Actually you’re likely to have to do some debugging.

    The solution – possibly

    <IfModule mod_rewrite.c>
    RewriteRule On
    RewriteBase /
    
    # Redirect the subdomain to a directory.
    RewriteCond %{HTTP_HOST} ^imonline.techchef.co$ [NC] # NC = no case
    RewriteRule ^(.*)$ http://techchef.co/imonline/$1 [L]
    
    # Do not redirect actually existing files and directories. Optional?
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    
    # Redirect everything to index.php, your last RewriteRule of your current .htaccess
    RewriteRule . index.php
    </IfModule>
    

    The last RewriteRule depends on your CMS. I have little experience with WordPress, so I cannot tell. You may find respective information online.

    As a matter of fact, a quick google search would have yielded the correct .htaccess. There are multiple templates for different scenarios here. Scroll down a bit to find one for subdomains.

    I hope you could at least learn something… 😛