Forum Moderators: phranque
I want to redirect all requests (including the parameters after the URL) for
http://domain.com/sub/ to http://sub.domain.com/. The problem is that THEY SHARE THE FOLDER. I've tried multiple solutions, but they all failed. Any ideas?
HTTP_HOST is only the domain name, so knock the folder off the end. I assume you would want it to also redirect for
www.example.com so change that bit to ^(www\.)?example\.com too. You can now place this code in the .htaccess file inside the folder - or you can add
^forum/ to the start of the rule checking and then place it in the .htaccess in the root of the main domain -- your choice. [edited by: jdMorgan at 12:09 am (utc) on Oct. 28, 2008]
[edit reason] Please use example.com [/edit]
http://domain.com/sub/, it redirects to http://sub.domain.com/ correctly. However, If I omit the trailing slash (so the URL looks like http://domain.com/sub), the redirection redirects to http://sub.domain.com//home/USERNAME/public_html/sub, which returns a 404 error. Any ideas? And as for the www. thing - I already have a .htaccess in my main root that redirects the URL to the non-www version.
So, fix both problems in the one rule when it is www.domain.com/forum/ that is requested. After that, list your "general" www rule that fixes all of the other requests.
[edited by: g1smd at 12:22 am (utc) on Oct. 28, 2008]
Check the other of your rules: Redirects first, from specific to general, and then rewrites last.
Check a variety of both expected and unexpected URLs: both domains, and subdomains, for both www and non-www, and all both with and without trailing slash, and so on, and use Live HTTP Headers for Mozilla Firefox to check that you get the correct responses back.
[edited by: g1smd at 12:34 am (utc) on Oct. 28, 2008]
The way to prevent that is to check the client request header using a RewriteCond to test %{THE_REQUEST}, and only redirect back to the subdomain URL if it was the client that requested the subdomain-named folder, rather than that URL being requested as a result of the previously-invoked internal rewrite.
This is why I said "it's not a problem" at the outset. However, I didn't say "It's simple"... :)
Jim