1
votes

i get the source code from Stackoverflow-Using wildcard subdomain on specific directory

original code:

    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.domain\.com$ [NC]
    RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
    RewriteRule ^(.*)$ /%1/$1 [L]

it's work properly, but the code above is pointing the directory from root. i want all subdomain point to the directory which is in my "portfolio" directory, so i try modify myself the code

after modify(added "/portfolio"):

    RewriteEngine on
    RewriteBase /

    RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.mlaxproject\.com$ [NC]
    RewriteCond %{REQUEST_URI}::%1 !^/([^/]+).*?::\1
    RewriteRule ^(.*)$ /portfolio/%1/$1 [L]

but it give me "500 -Internal Server Error" ... why? can anybody correct my code?

Thank and sorry for my english.

1

1 Answers

1
votes

You need to add /portfolio to your RewriteCond too.

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^(?!www\.)([^.]+)\.mlaxproject\.com$ [NC]
RewriteCond %{REQUEST_URI}::%1 !^/portfolio/([^/]+).*?::\1
RewriteRule ^(.*)$ /portfolio/%1/$1 [L]