M
M
mstarrr2011-12-29 16:58:12
Regular Expressions
mstarrr, 2011-12-29 16:58:12

Mod_rewrite regex for subdomain?

There are domains en.auto.lc, auto.lc, en.auto.mstarproject.com, auto.mstarproject.com
It is necessary that the “en” parameter be passed to QUERY_STRING on the server, preferably. You can transfer the entire HTTP_HOST, in PHP I will destroy this parameter.
I'm tinkering, it just doesn't work. Here's roughly what you need:

RewriteCond %{HTTP_HOST} ^en\.auto\.(.*)$<br/>
RewriteCond !%{QUERY_STRING} (.*)locale_subdomain(.*)<br/>
RewriteRule ^(.*)$ /$1&locale_subdomain=%{HTTP_HOST}<br/>

My rule does not work, I understand why. I'm poking around, I can't make it work.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
DmitryKuzmenkov, 2011-12-29
@DmitryKuzmenkov

You just need to change the rewrite conditions from QUERY_STRING to HTTP_HOST:
RewriteCond %{HTTP_HOST} ^(en)\.auto\..+$
RewriteRule ^(.*)$ /$1&locale_subdomain=%{HTTP_HOST}

A
Anton, 2011-12-29
@sHinE

So you have a host and so in php it will be in $_SERVER, if the domains are configured for one folder - and then sort it out as it should.

H
himik, 2011-12-29
@himik

Isn't it easier to sort it out at the level of the router of the framework?

M
mstarrr, 2011-12-29
@mstarrr

This is how it turned out, only somehow long to list all the folders that are on the server and can potentially appear:
RewriteCond %{REQUEST_URI} !^/[^\/]+.php
RewriteCond %{REQUEST_URI} !^/[^\/]+.xls
RewriteCond %{REQUEST_URI} !^/image/
RewriteCond %{REQUEST_URI} !^/imbbank/
RewriteCond %{REQUEST_URI} !^/robots.txt
RewriteCond %{REQUEST_URI} !^/mpanel/
RewriteCond %{REQUEST_URI} !^/js/
RewriteCond %{REQUEST_URI} !^/css/
RewriteCond %{REQUEST_URI} !^/libp/
RewriteCond %{REQUEST_URI} !^/single/
RewriteCond %{HTTP_HOST} ^en\.auto\.(.*)$
RewriteCond %{QUERY_STRING} !(.*)locale(.*)
RewriteRule ^(.*)$ /?locale=en&%{QUERY_STRING}

M
mstarrr, 2011-12-29
@mstarrr

In, it looks like he finished it: how will this option work?
RewriteCond %{REQUEST_URI} !^/[^\/]+.(.*)
RewriteCond %{HTTP_HOST} ^en\.auto\.(.*)$
RewriteCond %{QUERY_STRING} !(.*)locale(.*)
RewriteRule ^(.*)$ /?locale=en&%{QUERY_STRING}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question