You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.htaccess配置www跳转后URL自动追加/public_html/的问题求助

Fixing the Unintended /public_html/ Redirect in Your .htaccess WWW Rule

Hey there, let's troubleshoot why your www redirect is sending you to http://www.arnaldpedros.com/public_html/ instead of the clean root URL. This is a super common issue tied to how your server's document root is configured and where your .htaccess file lives—here's how to fix it, step by step:

First, Check Your .htaccess Location

Most hosting setups (like cPanel) set your website's document root to the public_html folder. If your .htaccess file is placed in the parent folder above public_html, the server will interpret paths relative to that parent directory, which is why it's adding /public_html/ to the redirect.

Fix: Move your .htaccess file directly into the public_html folder if it isn't already there.

Update Your Rewrite Rule for Reliability

Your original rule is close, but using $1 can sometimes pick up unintended path context if the server's base isn't set correctly. Try one of these more robust versions:

Option 1: Use %{REQUEST_URI} for Exact Path Matching

This uses the server's built-in variable to grab the exact requested path, avoiding any base path confusion:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.arnaldpedros\.com$ [NC]
RewriteRule ^ http://www.arnaldpedros.com%{REQUEST_URI} [L,R=301]

Option 2: Add RewriteBase / to Set the Root

If your server needs an explicit base path declared, adding RewriteBase / ensures all rewrite rules use the document root as the starting point:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.arnaldpedros\.com$ [NC]
RewriteRule ^(.*)$ http://www.arnaldpedros.com/$1 [L,R=301]

Critical Step: Clear Browser Cache

301 redirects are cached aggressively by browsers. Even after fixing the rule, you might still see the old /public_html/ path until you clear your browser's cache (or test in incognito mode to bypass cached redirects).

For Multiple Sites

Since you said this affects all your websites, check two things across all accounts:

  • Every site's .htaccess is in its respective public_html folder (the document root).
  • Your hosting panel (like cPanel) doesn't have conflicting redirect settings. Many hosts offer a built-in "Redirect to WWW" tool in the domain settings—using this can avoid manual .htaccess path issues entirely.

Bonus: Check for Rule Conflicts

If you have other rewrite rules in your .htaccess, make sure this www redirect rule is at the top of the file. Earlier rules might be modifying the request path before this rule runs, causing unexpected behavior.

内容的提问来源于stack exchange,提问作者piedracita

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:36:55