I have the following .htaccess content:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(.*)\.*(.+)
RewriteRule ^((?s).*)$ index.php?_uri=/$1&_subdomain=%1&_host=%3 [QSA,L]
I want to get subdomain of the url(if it exists), but when I add a quantifier to \., the result of _subdomain is example.localhost instead of example.
The full url is example.localhost.
Anyone can explain to me?
Use ^(.*)\.(.+)
Your current regex is making the . optional, while it should be required exactly once. Since \.* matches 0 or more times, therefore the greedy matching of ^(.*) is capturing everything up to the last character that is matched by (.+)