# Subdomain on hosting with rewrite

**URL:** <https://discourse.cakephp.org/t/subdomain-on-hosting-with-rewrite/10174>\
**Category:** Need Help\
**Created:** [February 18, 2022, 4:36pm UTC](https://discourse.cakephp.org/t/subdomain-on-hosting-with-rewrite/10174 "2022-02-18T16:36:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [February 18, 2022, 4:36pm UTC](https://discourse.cakephp.org/t/subdomain-on-hosting-with-rewrite/10174/1 "2022-02-18T16:36:19Z")

</div>

I have in root hosting .htaccess  
to be able to use different domains or subdomains on one hosting.

```auto
RewriteEngine On

# full domain (alias)
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI]

# subdomain (with or without www)
RewriteCond %{REQUEST_URI} !^subdom/
RewriteCond %{REQUEST_URI} !^/subdom/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)\.([^\.]*)\.([^\.]*)$
RewriteCond %{DOCUMENT_ROOT}/subdom/%2 -d
RewriteRule (.*) subdom/%2/$1 [DPI]

# alias
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]

# subdomain
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^subdom/[^/]+/(.+[^/])$ /$1/ [R]

```

and folders:

```auto
domain
subdom

```

In folder `subdom` i have folder `test`

In the test folder i have php cake… its work, but the links point to url `/subdom/test/contact`  
I need the links to point to `/contact`

If the set in app.php:

```auto
    'App' => [
        ...
        'base' => '/',
        ...
    ],

```

Url is ok, but a route matching “contact” could not be found.

Thank You!
