redirecting url from one subfolder to another using conf file / ubuntu

坚强是说给别人听的谎言 提交于 2019-12-13 06:22:44

问题


I have web site on domain.com which is located at /var/www/main

I also have started another web site which I want to be on url domain.com/a/b But the actual file location is /var/www/main/a/b/c

Problem is that I want the users to use url domain.com/a/b and get files from /var/www/main/a/b/c

So I've found domains conf file at /etc/apache2/sites-available/domain.com.conf

It had only this

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
</virtualhost>

Now after reading different topics about it I've tried to add this so now my domain.com.conf file looks like this

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
</virtualhost>

<virtualhost *:80>
    ServerName domain.com
    ServerPath /a/b/
    DocumentRoot /var/www/main/a/b/c
    RewriteEngine On
    RewriteRule ^(/a/b/.*) /var/www/main/a/b/c
    # ...
</virtualhost>

But this does not work at all. What am I doing wrong ?


回答1:


No need for Rewrite Rules. Just set up an alias in /etc/apache2/sites-available/domain.com.conf :

<virtualhost *:80>
    ServerName domain.com
    DocumentRoot /var/www/main
    Alias /a/b /var/www/main/a/b/c
</virtualhost>

Then restart apache :

$ sudo service apache2 restart


来源:https://stackoverflow.com/questions/20982145/redirecting-url-from-one-subfolder-to-another-using-conf-file-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!