ruby-on-rails.htaccessmod-rewritewildcard-mapping

wildcard_charcters.sitename routing issues


i would like to incorporate wildcard characters to my site. so previously it was www.mysite.com/user/mike or www.mysite.com/user/dave will look like mike.mysite.com or dave.mysite.com. i tried .htacces rewriting but those were of rewriting for sub-domains and it was creating problems with css and images.I just want that too call user function with value we pass.I use RoR MVC framework.(i'm sure .htacces solve this issue but i don't know if we can give wildcards in routes too).

and i would like to keep other links normal like www.mysite/project/dashboard or www.mysite/project/messages.

Thanks in advance.

edit

i tried this but it dosent work, it's goes to site5s default page.

Options +FollowSymLinks
RewriteEngine On
RewriteCond ^(.*)$.example.com  [NC]
RewriteRule ^(.*)$ http://example.com/user/$1 [R=301,L]'

Solution

  • ok, finnaly i was able to do it,there will be few things which you have to do first.

    paste this code in .htaccess first of all.

    Options +FollowSymLinks
    RewriteEngine On
    // enable rewriting
    RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$  // Check for wildcard character before example.com
    RewriteCond %1 !=www  // check if www is not present in URL
    RewriteRule ^(.*)$ http://www.example.com/user/%1/$1 [R=302,L]  // Redirect URL and replace matched wildcard character "^(.+)" in place of "$1"
    

    Now we have defined the rules for that, now it's turn of redirection. above code won't be able to work. for that you have to create a wildcard sub domain in from your Cpanle. Create a sub domain *.example.com and point to your public_html(you subsite if t\redirected site is a child site)