开发者

Is there a way to create subdomain like url redirection using .htaccess?

开发者 https://www.devze.com 2022-12-21 20:42 出处:网络
I want to write a .htaccess from which the following action should be done. I 开发者_StackOverflow社区have domain like

I want to write a .htaccess from which the following action should be done.

I 开发者_StackOverflow社区have domain like

www.xyz.com 

and am putting many articles on that. so it wil become

www.xyz.com/article1-tutorial/
www.xyz.com/article2-tutorial/
www.xyz.com/article3-tutorial/

But instead of that i need like this.

www.article1-tutorial.xyz.com/
www.article2-tutorial.xyz.com/
www.article3-tutorial.xyz.com/

Please help to find the solution. I know we cant go for subdomain concept and only the way is redirection. So whats is the solution?


You'll need something like this in your apache.conf:

<VirtualHost *:80 >
        ServerName automated_domains
        ServerAlias *.xyz.com
        VirtualDocumentRoot /home/xyzcom/website/
</VirtualHost>

Then in the PHP file you put in /home/xyzcom/website, you can get the domain that was actually called in the $_SERVER['HTTP_HOST'] variable.

Hope this helps!

KKovacs


You can use apache's mod rewrite like so:

   RewriteEngine On
   RewriteBase /
   RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
   RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
   RewriteRule (.*) %2/$1 [L]

when a user goes to http://article1-tutorial.domain.com/ server internaly rewrites therequest to http://www.domain.com/article1-tutorial


Can you use the reverse proxy engine of apache?

Reverse Proxying with Apache

0

精彩评论

暂无评论...
验证码 换一张
取 消