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
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
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. 😉
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.You don’t use a
RewriteCond %{HTTP_HOST} ^subdomain.domain.tld$
followed by an appropriateRewriteRule
.Your previous attempt would redirect every request to the subdomain and simply end there due to the
[L]
flag.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.RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
should redirect everything within thewp-admin
directory to thewp-admin/index.php
file, which isn’t necessarily what you want.wp-admin/edit/article
would also be routed towp-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
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… 😛