修改Rewrite规则:将代理功能从主站迁移至子目录
Adjusting .htaccess Rewrite Rules for Proxy in Subdirectory
Got it, here's how to tweak your .htaccess rules so the proxy works when both files are in a subdirectory named folder:
First, replace your existing .htaccess code with this adjusted version:
RewriteEngine on RewriteBase /folder/ RewriteRule ^(.*)$ proxy.php?url=$1 [L,QSA]
Key changes explained:
- Updated
RewriteBase: Changed from/to/folder/— this tells the web server that all rewrite rules in this .htaccess apply to thefoldersubdirectory, not the site root. - Simplified target path: Since both the .htaccess file and
proxy.phplive directly insidefolder, we can referenceproxy.phpby its filename alone in the RewriteRule target, no extra directory path needed.
Quick verification steps:
- Drop the modified
.htaccessand your existingproxy.phpfile into thefoldersubdirectory at your site's root. - Test by visiting
www.domain.com/folder/(or append a target URL likewww.domain.com/folder/your-target-site.comto confirm the proxy functionality works as expected).
内容的提问来源于stack exchange,提问作者Andy Fletcher
相关产品推荐
相关产品推荐

