问题原文
原帖链接 · Michael Samuel · CC BY-SA 3.0
I have an htaccess in a subdomain with the following rule:
RewriteEngine On
RewriteBase /
RewriteRule ^feed([0-9]+)$ ../image.php?id=$1 [L]
So basically I want to redirect requests from feed which is located in a subdomain to image.php file which is located in the main domain (just one directory above). Using ../ doesn't seem to work like in PHP.
So how can I rewrite to file in the parent directory?
已采纳解答
原帖链接 · MrWhite · CC BY-SA 3.0
By the sounds of it, you are already in the document root of your subdomain, which is probably defined in its own virtual host (which happens to point to a subdirectory off the main domains document root).
Unfortunately, you can't internally rewrite above/outside the document root using mod_rewrite in .htaccess. In .htaccess the RewriteRule substitution takes a URL-path only, not a filesystem path. However, you can do this if you are using mod_rewrite directly in the server config. In the server config you can specify a filesystem path as the substitution (you would need to explicitly include the full path, you can't use a relative path like ../image.php).
Alternatively, in .htaccess you might be able to proxy the request from your subdomain to the maindomain using mod_proxy with mod_rewrite. However, this might still require some server configuration. For example:
RewriteRule ^feed([0-9]+)$ http://maindomain.com/image.php?id=$1 [P]
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
