-1

I'm confuse, how to make a fake subdomain,

let's say I want to make a fake subdomain like

http://subdomain.example.com/category/my-url-category

but that fake subdomain read data from

http://www.example.com/category/my-url-category

I'm using CI as my framework, and I've try on the .htaccess like this

RewriteCond %{HTTP_HOST} !example.com
RewriteRule (.*) /index.php/subdomain/category/%{HTTP_HOST}/$1 [L]

But it's not work

Thanks in advance

adeade
  • 317
  • 5
  • 12
  • these other 'so' questions may be useful: **[htaccess-subdomain](http://stackoverflow.com/questions/5445978/htaccess-subdomain)**, **[Create Subdomains on the fly with .htaccess (PHP)](http://stackoverflow.com/questions/586129/create-subdomains-on-the-fly-with-htaccess-php)** – Ryan Vincent Apr 05 '14 at 05:07

1 Answers1

0

For subdomains to work, you'll need to change your dns to translate said subdomain to your site. This is done with a CNAME record. Typically your DNS looks something like this:

Domain           Type       Target
example.com      A          192.168.1.0
*.example.com    CNAME      example.com

*.example.com will route this.example.com and that.example.com to the ip defined for example.com, but this.other.example.com is not matched by it. If you just want to have one subdomain, make a CNAME record for just that subdomain instead (not with a *).


In httpd.conf (this is the main config file for Apache, might be named differently on your operating system) make sure your subdomains are using the same document root. I am not familiar with this, but this might help according to this.


In .htaccess in your www-root have the following rule:

RewriteCond %{REQUEST_URI} !^/index\.php
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$
RewriteRule ^(.*)$ /index.php/subdomain/category/%1/$1

This will internally rewrite somename.example.com/whatever/thing to DOCUMENT_ROOT/index.php/subdomain/category/somename/whatever/thing.

Sumurai8
  • 20,333
  • 11
  • 66
  • 100