1

Basically I have this htaccess:

Options +FollowSymLinks
Options -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ([a-z0-9-]+).([a-z0-9-]+)([/admin])? [NC]
RewriteRule ^$ index.php?domainusr=%1 [L]

Imagine that the subdomain will be a User, and I want to get that user. But the thing is this htaccess will work, with some drawbacks:

My question is: How can I have this subdomain as a GET parameter in EVERY accessable content, without interfering with others GETs?

  • 1
    Not a solution but a proposal: why not using something like [this](http://stackoverflow.com/questions/5292937/php-function-to-get-the-subdomain-of-a-url#answer-11127956) to get the subdomain instead of adding a GET parameter? – Christian Fries Nov 24 '14 at 12:07
  • It will indeed work, but I really wanted to see a solution using mod-rewrite. But thanks! – Nilton Frederico Teixeira Nov 24 '14 at 12:17

1 Answers1

3

If you want to add ?domainusr=%1 to all your links, with this .htaccess:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ([a-z0-9-]+)\.domain\.com [NC]
RewriteRule ^(.*)$ $1?domainusr=%1 [QSA,L]
Croises
  • 18,570
  • 4
  • 30
  • 47