What would be a good way of rewriting these types of urls (via a wildcard subdomain): http://somedomain.com/263-NYC-Manhattan to http://nycmanhattan.somedomain.com or http://somedomain.com/116-Chicago to http://chicago.somedomain.com or http://somedomain.com/365-Houston to http://huston.somedomain.com etc. etc. etc. Basically, it needs to omit the numbers and dashes.
I found 2 solutions that might work however I don't think they're stripping the numbers and dashes. Any ideas what needs to be adjusted? RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$ RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -f [OR] RewriteCond %{DOCUMENT_ROOT}/%1%{REQUEST_URI} -d RewriteRule ^(.*)$ /%1/$1 [QSA] Or: RewriteEngine On RewriteCond %{HTTP_HOST} !^www\.mywebsite\.com$ RewriteCond %{HTTP_HOST} ^(\w+)\.mywebsite\.com$ RewriteCond %{REQUEST_URI}:%1 !^/([^/]+)/([^:]*):\1 RewriteRule ^(.*)$ /%1/$1 [QSA] Code (markup):
Not sure, but depending on the amount of URL's you need to redirect you might be better off just by using a standard Redirect than going through all the trouble that wildcard can be e.g Redirect 301 /263-NYC-Manhattan http://nycmanhattan.somedomain.com Redirect 301 /116-Chicago http://chicago.somedomain.com Redirect 301 /365-Houston http://huston.somedomain.com Let me know if that's any help
I abandoned the entire wildcard idea. If one has 5-10 wildcard re-directs it's all fine. But when you have to deal with something like 700 of them it's a completely different story as it will eat up all your resources and available user connections. But I agree, what you're suggesting is a better way to go about it.