gerkintrigg Posted July 13, 2012 Share Posted July 13, 2012 Hi all, I want to have a similar kind of functionality to a lot of sites where I make a sub-folder of a domain (like www.whatever.com/subfolder). I know how to use .htaccess to rewrite (limited knowledge, I admit) but my problem is that I need the server to work out when the folder is a folder and when it is a database record. I've Googled things like "parse PHP in .htaccess" but keep drawing a blank there. How do so many sites (Like Facebook) do it? Thanks, Neil Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/ Share on other sites More sharing options...
requinix Posted July 13, 2012 Share Posted July 13, 2012 Do you want a subfolder or a subdomain? Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361230 Share on other sites More sharing options...
gerkintrigg Posted July 13, 2012 Author Share Posted July 13, 2012 Either would work for my purpose, but I was thinking a sub folder might be better. Which is easier? The sub folder I was thinking of would be something like: http://www.truro.com/gerkintrigg I suppose a subdomain like: http://gerkintrigg.truro.com would work too, but I'd prefer the first example if possible. Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361235 Share on other sites More sharing options...
requinix Posted July 13, 2012 Share Posted July 13, 2012 Use URL rewriting with a "the request doesn't exist" condition. That means virtual folders like "images" or "style" wouldn't work if they were actual directories on your site. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ... Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361356 Share on other sites More sharing options...
gerkintrigg Posted July 13, 2012 Author Share Posted July 13, 2012 That sounds perfect but I'm not sure how to do what you've said at all. I expected my rules to look a bit like this: RewriteEngine on RewriteRule ^(.*) sites/index.php?page_name=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361360 Share on other sites More sharing options...
Jessica Posted July 13, 2012 Share Posted July 13, 2012 I believe you add those two lines above your current rule. Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361375 Share on other sites More sharing options...
gerkintrigg Posted July 13, 2012 Author Share Posted July 13, 2012 Awesome! You guys are truly amazing! And Thanks (Obviously) Quote Link to comment https://forums.phpfreaks.com/topic/265601-dynamic-subdomains/#findComment-1361376 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.