开发者

.htaccess subdomain to folder

I've recently made some minor changes to my website's folder structure, and now one of my rewriterules seems broken.

in the past I had a /mydomain.com/ folder in public_html in which a wiki was set up. In the same folder were some folders that I used for subdomain access, like members and files.

The old setup:

#www to main website
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ mydomain.com/$1 [L]

#subdomain to folder (members. => /members/, files. => /files/, etc)
RewriteCond %{HTTP_HOST} ^(.*).mydomain.com$
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ mydomain.com/%1/$1 [L]

Fairly easy, and when I typed in files.mydomain.com/myfile.zip it worked without any problems.

Recently I installed several languages of my wiki (which is in fact irrelevant to the question, but just to elaborate the situation) and I made the following rule:

#to the right language folder (www = en)
RewriteCond %{HTTP_HOST} ^(www|nl|es).mydomain.com$
RewriteRule ^(.*)$ mydomain.com/%1/$1 [L]

#subdomain to folder (members. => /members/, files. => /files/, etc)
RewriteCond %{HTTP_HOST} ^(.*).mydomain.com$
RewriteCond %{HTTP_HOST} !^www.mydomain.com$
RewriteRule ^(.*)$ mydomain.com/misc/%1/$1 [L]

Obviously, the different language wikis are set up in mydomain.com/www/, mydomain.com/es/, etc. This works perfectly fine. The problem lies in the second part, the subfolders. In the same mydomain.com/ folder I created a misc/ folder to store all the misc stuff (including the subdomain folders). I figured just adding the /misc/ in the path (like I added the language folder name in the first rule) would make it work.. but it gives me a 500 error. Neither the old setup nor the new setup have any .htaccess lines in any folders that could conflict with the second rule.

Can anyone sp开发者_StackOverflowot the error, or tell me how to systematically check this setup for bugs?


The easiest way to prevent the redirection loop I believe is happening is to just check if you've already rewritten the URL to where you intended it to go. We can do this a few different ways; if you know that the file will exist once you've rewritten it, you can condition on %{REQUEST_FILENAME} !-f, for instance.

In your case, since you're rewriting everything to a common folder within your /public_html directory, we can just check if that's already been done:

#to the right language folder (www = en)
RewriteCond %{HTTP_HOST} ^(www|nl|es)\.example\.com$
RewriteCond %{REQUEST_URI} !^/example\.com
RewriteRule ^(.*)$ example.com/%1/$1 [L]

#subdomain to folder (members. => /members/, files. => /files/, etc)
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteCond %{REQUEST_URI} !^/example\.com
RewriteRule ^(.*)$ example.com/misc/%1/$1 [L]

Admittedly, I'm not sure why you're experiencing issues now, but weren't before. I ran your original rule set on my test server and ended up with an internal server error due to too many internal redirections, so there must be differences in our setup. In any case though, hopefully this will get things working for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜