Reputation: 620
I have to get the subdomain of my domain (example: d3strukt0r.orbitrondev.com/forum.php)
So, of the example i have to get d3strukt0r
and access the directory: /service/d3strukt0r/www/forum.php
This has to work with .htaccess
I already tried it with this code:
RewriteCond %{ENV:REDIRECT_SUBDOMAIN} =""
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.orbitrondev\.com\.?(:80)?$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^(.+?)/?$ /service/%1/www/$1.php [E=SUBDOMAIN:%1,L]
what came out was:
The requested URL /forum.php was not found on this server.
So my code accessed instead of /service/d3strukt0r/www/forum.php
this /forum.php
EDIT
It worked with this
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.orbitrondev\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/service/%1/www/$1 -f [NC]
RewriteRule ^(.*)$ /service/%1/www/$1 [L]
The problem is, when I access a folder http://d3strukt0r.orbitrondev.com/folder/
it accesses /folder/
instead of /service/d3strukt0r/www/folder/
How can i fix this problem?
Upvotes: 2
Views: 111
Reputation: 785108
SUBDOMAIN
env variable since you are checking for existence of .php
extension anywayHTTP_HOST
variableHTTP_HOST
starting with www.
You can use this rule:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z0-9][-a-z0-9]+)\.orbitrondev\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/service/%1/www/$1.php -f [NC]
RewriteRule ^(.+?)/?$ /service/%1/www/$1.php [L]
Also make sure you're visiting this URL:
http://d3strukt0r.orbitrondev.com/forum
i.e. without .php
in the end.
Upvotes: 1