url rewriting subdomain to subdirectory

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pedja
    Senior Member
    • Mar 2004
    • 329

    #1

    url rewriting subdomain to subdirectory

    I have domain mydomain.com and I have added subdomain subdmain.domain.com through cpanel. It works but I want to force that ef someone access subdomian.domain.com he is forwared to www.mydomain.com/subdomain/. I wnat this as redirection so new url is shown in visitors browser address field.

    i've created .htaccess and placed it no root of the domain.com. Its contents is this:

    RewriteEngine on
    RewriteRule ^subdomain\.domain\.com(.*) www.domain.com/subdomain/$1 [R]

    It does not work. What Am I doing wrong. Is itpossible that cpanel already set some url rewriting in this case and it overrideds my rules?
  • ZYV
    Senior Member
    • Sep 2005
    • 315

    #2
    I would place something like

    RewriteEngine on
    RewriteRule (.*) http://www.domain.com/subdomain/$1 [R]
    (notice the http:// part) in .htaccess in the subdomain folder. This seems to be a less ressource intensive rule and it should work fine. Fairly sure it should work this way, but can't check it myself right now. Besides, cPanel offers you a redirection service on the subdomain management page.

    Comment

    • Pedja
      Senior Member
      • Mar 2004
      • 329

      #3
      I think your urle redirects any subdomain to specific directory. What i need is to redirect specific subdoman to directiry named as subdomain.

      I know about redirect in Cpanel, but I want to be sure that I use 301 redirection.

      Comment

      • ZYV
        Senior Member
        • Sep 2005
        • 315

        #4
        No, this is not completely true. If you place an .htaccess file like this in a folder, it will redirect the requests to this directory to the given directory.

        So, if you create a subdomain foo.bar.com and specify a folder subfoo via cPanel, then drop the .htaccess above to the subfoo folder and create a foo folder under your public_html this will do exactly what you need: redirect foo.bar.com to http://www.bar.com/foo/.

        I think cPanel now allows you to create a subdomain within an arbitrary subfolder under your public_html. The only objection to my solution above I foresee is that it's not elegant, but mind you, it gives you more speed that just one global .htaccess in you public_html solution.

        P.S. As for cPanel redirection, AFAIK it's based on mod_rewrite so all you have to do is to check the .htaccess it created afterwards to ensure it uses 301. You could also use a sniffer or FireBug/Webdev FF extensions though.

        Comment

        • Pedja
          Senior Member
          • Mar 2004
          • 329

          #5
          I had a problem that redirection did not work at all. On my other site, which uses straight domain )no subdomain) i have more complex redirection with url parsing and ot works. So I was confused.

          Ichecked CPanel redirection option and it seems it is a bit improoved in this new version. It actually allows one to choose if 301 redirection is used. I set it up and it works fine.

          Comment

          Working...