Forum Moderators: phranque
I am trying to do rewrite internally for folder to his same folder but in subdomain:
domain.com/folder_real -> folder_real.domain.com
subdomains are being setup manually in the server to the real folder path (/public_html/folder_real).
My code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^([0-9]+)\.(.*)$ [NC]
RewriteRule ^/?([0-9]+)/(.*)$ [$1.domain.com...] [L]
Code works. However, in external method- and I want to do rewrite internally by the server.
I tried to replace line #3 to:
rewriteRule (.*)/([0-9]+)/(.*) $2.$1/$3 [L]
but without success.
Hope to get some help over here.
Thank you.
Further, your URL-design is non-optimal, and I'm not at all sure that this is a good idea. You might want to post in one of our Webmaster forums and describe your goals. It would be a good idea to discuss *what* you want to do before trying to discuss *how* to do it (in code).
A normal approach would be to set up subdomains, point them all to the same virtual server, and then use code to map (internally) those subdomain requests into subfolders -- without revealing in the URL that those subfolders even exist. Your description and code seem to take an almost opposite approach -- One that I can't think of a good reason to do.
Jim
Basically, I did it for Awstats. I need to get stats from one specific folder that is seperated from my website. However, on awstats configuration file I can set only domains and subdomains (i don't know how to set for folder). Therefore, I decided to open a new subdomain for this folder. However, I saw that awstats won't count if you enter using the physical folder and not the subdomain (only if you enter test.domain.com it will count but not if you enter same folder but using domain.com/test). I could redirect to the new subdomain but I have already too many embeded links that use the old link with the physical folder (domain.com/test) and it's a bigger issue for me to change all links to the new one (test.domain.com) so I decided to use rewrite mod:
If people will enter old link it will go to the same folder using subdomain but without redirecting (browser redirecting will cause problems for embeded media).
Link structure for rewrite mod:
[domain.com...]
to
[variable_Number.domain.com...]
(subdomain configured in cpanel to /public_html/permanent_folder_NAME/variable_Number/ )