URLs to subdomains via .htaccess

Discussion in 'Apache' started by qwikad.com, Feb 26, 2016.

  1. #1
    qwikad.com, Feb 26, 2016 IP
  2. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,278
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #2
    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):
     
    qwikad.com, Feb 26, 2016 IP
  3. Eduardo Leoni

    Eduardo Leoni Greenhorn

    Messages:
    1
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    11
    #3
    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
     
    Eduardo Leoni, Mar 7, 2016 IP
    qwikad.com likes this.
  4. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,278
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #4
    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.
     
    qwikad.com, Mar 8, 2016 IP