Absolute file paths in mod_rewrite - allowed?

久未见 提交于 2020-01-04 04:16:07

问题


This is a follow-up to this question.

I am trying to build a mod_rewrite rule where the rewriting target is an absolute path outside the web root, like

RewriteRule ^manual(/(.*))?$ /www/htdocs/customername/manual/$2 [L]

I need to do this because I can't use Alias in a .htaccess context (shared hosting).

There are responses hinting at this not being possible at all.

Is this true? I can't find any clear info in the manual.

Could somebody clarify when absolute paths are possible, and when they are not?


回答1:


It is certainly possible to use absolute file paths in your server config.

You won't be able to do that in a .htaccess file though, since that would give you access to read files outside your document root, even files from other customers that were supposed to be protected by a <Location ...> block.




回答2:


The replacement in a RewriteRule is a URL path. An absolute path in the replacement is an absolute URL path, not an absolute file path. If you can't reference a resource (i.e. it doesn't have a URL), then the rewrite engine can't help you.

Instead, try creating a symlink, though you'll need the FollowSymLinks or SymLinksIfOwnerMatch option enabled. If you don't have shell access, you can write a script to create symlinks.



来源:https://stackoverflow.com/questions/2191583/absolute-file-paths-in-mod-rewrite-allowed

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