In my current project, I was asked to provide blog feature for every registered user, that means when you register, you can automatically write blogs on site. This was easily done, however, I was instructed to use URLs in format like http://username.site.com
refering with username to specific user blog.
I am trying to achieve this with .htaccess file, but it seems my conditions are met but I am getting 500 Internal Server Error, wich is caused by infinite loop of rewrites. I would like to avoid that but I can't find suitable solution. Here is my .htaccess so far:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|tinymce|files|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-_]+).dev.example.com [NC]
RewriteRule ^(.*)$ /index.php/blog/%2/$1 [L]
</IfModule>
Additional info: The site is server hosted, but hidden and on dev.example.com
so blog URL's should look like username.dev.example.com
, when site will be launched, this will of course be username.example.com
. It's built with Codeigniter.
Any suggestions about improving that .htaccess would be great, thank you.