Rewrite Rule in .htaccess file for subdomain

Posted June 18, 2014 92.6k views
Hi, I have configured my Blog on For this I have an Apache Conf file which direct the user to /blog directory. I have two major issues: 1.) After installation, when I try to open admin panel from, it throws 500 Internal Server Error. It seems the rewrite engine is not properly coded in the .htaccess file. Also when I try to open the admin link, it takes me to: in place of This is bound to throw an error. 2.) When I open the site,, it opens normally, but when I click on the default 1st blog, again the Server throw 500 Internal Error and takes me to in place of I think it has something to do with .htaccess file which sends rewrite information to server, which is incorrect. Can you please advice what should be the edit for:
RewriteRule ^(.*)$ index.php/$1 [L]
so that I can remove index.php from the URL as well as keep the link to while browsing the blog?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
10 answers
Let's start simple: in your apache config (/etc/httpd/conf/httpd.conf or /etc/apache2/apache2.conf), do you have this uncommented:
NameVirtualHost *:80
If not, uncomment that, and restart httpd Next, most blogging software won't allow multiple domains in one folder. You'll need a separate folder per domain/sub-domain. If you're not doing this, you will need to separarate that. Almost done. Let's go back to the apache config (Look at my 2nd line for the file again) Do you have something like this for your vhost:
AllowOverride All
or is it something like this:
AllowOverride None
If the latter, it won't work, and you'll need to change it (This doesn't apply to the cgi-bin or error folders, just your document root). Next to last: do you have mod_rewrite enabled? For Ubuntu, you would run this:
a2enmod rewrite; service apache2 reload
Finally: do you have the permission set for the web user (apache/www-data) to have read access to your .htaccess file? If you're unsure of any of the answers to these questions, just let me know. Jon
Hi My .htaccess file which is placed in root of my blog installation which is working to an extent now:
#Options -indexes

<IfModule mod_rewrite.c>
	RewriteEngine On
	RewriteBase /

	# Allow any files or directories that exist to be displayed directly
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d

	# Rewrite all other URLs to index.php/URL
	RewriteRule ^(([a-zA-Z0-9_-]+)(/([a-zA-Z0-9_-]*))?)$ index.php?uri=$1&rewrite=page [L,QSA]

<IfModule !mod_rewrite.c>
	ErrorDocument 404 index.php
Even though I'm now able to stay on but I get errors: 1.) While I'm inside my blog's admin panel and trying to edit configuration. Now when I try to configure any setting, server throws "URL not found on sever" error. 2.) When I try to open admin panel from: it throws an error saying file not found. But interestingly, when i explicitly put a "/" in the end like: http://blog.example.som/admin/ it takes me to admin panel 3.) Point to be noted, that I have another .htaccess file sitting on the root of It means that I have two .htaccess files. One is sitting on the root of "" and other sitting on "". I don't know to what extent .htaccess file of would have effect on "" (read as It seems I'm nearing a solution, but not yet done! Now I'm stuck. Neither I'm able to create any new blog as admin nor I'm able make any changes into admin configuration. Any guesses?

Also Check this code for redirection with .index.htm to non www url

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{HTTP_HOST} !^ [NC]

RewriteRule ^(.*)$$1 [L,R=301]

RewriteCond %{REQUEST_URI} ^(.*)//(.*)$

RewriteRule . [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.htm\ HTTP/

RewriteRule index\.htm$ [R=301,L]\

Hi Checklist: 1.) Apache2.conf (CHECK) 2.) AllowOverrideAll (CHECK) 3.) mod_rewrite enables (CHECK) Pls advice what should be the correct code in .htaccess file. In my .htaccess file I have a code
RewriteRule ^(.*)$ index.php/$1 [L]
that Rewrites URL and remove index.php. But that's the catch. Once it removes index.php, it also remove any subdomain identifier take takes it back to "www". Pls advice correct code for .htaccess for subdomain redirection....
 RewriteCond %{HTTP_HOST} !^$
 RewriteCond %{HTTP_HOST} ^blog\$
 RewriteRule ^/(.*)$1 [L, QSA]
That should work, but not knowing your layout, I'm having to guess a bit.
The rule I wrote says that it should take ANY non-existant file/folder and redirect it to index.php/$1 if you don't add a "/" at the end, it treats it as a file rather than a folder, so it falls under that rule, because you may have a folder named "admin", but not a file.
Hi While struggling I figured out that I'm a nood! :p I just copied your code and forgot to correct the space in:
RewriteRule ^/(.*)$1 [L, QSA]
I again tried the correct code after removing the space:
RewriteRule ^/(.*)$1 [L,QSA]
and it did worked. Although now it is working with most of the features, yet, the "/" problem exists. I'm using a 'stop-gap' arrangement by putting a "/" in front of to ensure I reach my Admin Panel however that is something not 'pro'. Can you suggest a remedy so that even if I don't put "/" it should still understand the URL? Unfortunately, the blog code forum not answering at all :(. There exists another peculiar issue, all the links generated on the Admin Panel through blog code, when clicked, send me to which throws an error. Ain't these link bound to follow rules set in .htaccess file. I know I might be asking too much but I like things "the way they should be". Thanks for support in advance!

Is it wrtite code from www to non www version.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]