Htaccess subdomain mod-rewrite

I'm tired of this code

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.*)\.simasa\.cf
RewriteRule ^(.*)$ http://simasa.cf/sivutila/$1 [L,NC,QSA]

      

so, I want this code to do this: when I go to something .simasa.cf it needs to show me simasa.cf/sivutila/something/, but I don't want it to redirect

And the problem is that when I try to navigate to samppapro.simasa.cf (yes, http://simasa.cf/sivutila/samppapro exists) the browser gives me the following error: DNS_PROBE_FINISHED_NXDOMAIN

+3


source to share


1 answer


You need to use the backrefence on the RewriteRule that you matched the HTTP_HOST conditions. Also, if the main domain is on the same server, just use a relative URL. Try this rule.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.simasa\.cf
RewriteRule ^(.*)$ /sivutila/%1/$1 [L,NC,QSA]

      

See how it works. Also make sure your url is resolved by testing and entering the url in a browser.

You can also proxy display content on the backend or another domain, you will need to use mod_proxy

using [P] flag

to display the subdomain.



RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.simasa\.cf
RewriteRule ^(.*)$ http://simasa.cf/sivutila/%1/$1 [P,NC,QSA] 

      

Edit:

If you haven't configured subdomains in apache yet, you need to make sure apache is listening on all subdomains using a wildcard. *.simasa.cf

in a virtual host. How does apache know what you are looking for if you don't report it? You will also need to use a wildcard DNS record or create a DNS record for each subdomain you can use. Again, how do you end up in a subdomain that does not map to an IP address in DNS? Therefore, it will not work unless you configure the required requirements.

0


source







All Articles