.htaccess folder to virtual-folder rewriting

2020-07-18 04:56发布

Is it possible with Apache's RewriteEngine to do the following, and how?

This is the environment:

domain.com has a folder that contains a index.html page, htaccess is set to strip files so domain.com/folder/ opens domain.com/folder/index.html

Now what i need to achieve is display domain.com/folder/ content (the index.html) as it comes from domain.com/virtualfolder/ where virtualfolder does not exist and the url has to show as domain.com/virtualfolder/

I hope what i wrote it is understandable.

Thank you very much

3条回答
▲ chillily
2楼-- · 2020-07-18 05:04

You need an alias:

Alias /virtualfolder /full_path_to/domain.com/folder

See http://httpd.apache.org/docs/2.2/mod/mod_alias.html for more details.

查看更多
Fickle 薄情
3楼-- · 2020-07-18 05:17
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^virtual-folder/(.*)$ folder/$1 [QSA]
</IfModule>
查看更多
我欲成王,谁敢阻挡
4楼-- · 2020-07-18 05:18

Alias is the most convenient way, but it is required to put the alias in the httpd.conf. If you rent some web space, the provider will usually only allow you to edit the .htaccess file, and it´s no possible to put an alias in there. In that case, you need to work with mod_rewrite. Just have the same problem right now when typing it.

However, if you rent some web space and you got Plesk 11.5 or 12.0 installed, there´s usually an option "virtual directory" (if not deactivated)

查看更多
登录 后发表回答