.htaccess简易URL掩码失效,需配置domain.fr显示domain.it/fr内容
Hey Marco, let's fix that URL masking issue you're having with domain.fr. The key here is using reverse proxy instead of a simple redirect—since regular redirects will change the address bar, but reverse proxy lets you serve content from domain.it/fr while keeping domain.fr visible in the URL bar.
First, make sure your Apache server has these two critical modules enabled (they're required for reverse proxy functionality):
mod_proxymod_proxy_http
If you control the server, edit your Apache config file (like httpd.conf or apache2.conf) and uncomment these lines (or add them if they're missing):
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_http_module modules/mod_proxy_http.so
Then restart Apache to apply the changes.
Next, update the .htaccess file in your domain.fr root directory with this configuration:
# Disable open proxy to keep your server secure ProxyRequests Off # Only apply proxy rules to www.domain.fr requests <If "%{HTTP_HOST} == 'www.domain.fr'"> # Forward all requests to the French section of your domain.it site ProxyPass / http://www.domain.it/fr/ # Fix backend redirects to keep domain.fr in the address bar ProxyPassReverse / http://www.domain.it/fr/ # Optional: Preserve the original host header so your backend handles requests correctly ProxyPreserveHost On </If>
Let me break down what each part does:
ProxyRequests Off: Prevents your server from being used as an open proxy (this is a critical security measure).ProxyPass / http://www.domain.it/fr/: Tells Apache to send every request made to domain.fr directly to the/fr/path of your domain.it site.ProxyPassReverse / http://www.domain.it/fr/: If your domain.it site ever sends a redirect (like a Location header), this rewrites it to use domain.fr instead of domain.it—so the address bar never changes.ProxyPreserveHost On: Ensures the backend domain.it server receives the originalwww.domain.frhost header instead ofwww.domain.it—this helps if your domain.it site has any host-specific logic or restrictions.
If you previously tried a simple RewriteRule with the [R] flag (or no special flag), that's why it didn't work—those are redirects, not proxies. While you could use a RewriteRule with the [P] flag, the ProxyPass approach is cleaner for full-site proxying.
One last check: Make sure your domain.it server allows requests from domain.fr. If you have any host-based restrictions or CORS rules, add www.domain.fr to the allowed list so it doesn't block the proxy requests.
内容的提问来源于stack exchange,提问作者Marco Siino

