通过Google搜索访问Plesk搭建网站时重定向回Google问题排查
Let's break down the issue you're facing: your site loads fine when typing the domain directly, but clicking from Google search results sends you back to Google. Looking at your provided .htaccess file, the problem likely stems from how your redirect rules are structured, especially with the HTTPS enforcement and base path detection. Here's how to diagnose and fix it:
1. Fix the Hardcoded HTTPS Redirect
Your current HTTPS redirect rule forces all HTTP traffic to https://srad.wtf/es_ES/$1:
RewriteCond %{HTTPS} off RewriteRule (.*) https://srad.wtf/es_ES/$1 [R=301,L,QSA]
The issue here is that if Google has indexed pages without the /es_ES/ prefix, clicking those links triggers a forced redirect to the prefixed path. If your application isn't handling this correctly (or if there's a misconfigured route), it can create a redirect loop or unexpected behavior that sends users back to Google.
Solution:
Modify the redirect to preserve the original request path first, then let your application handle the language prefix routing:
RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L,QSA]
This ensures we only enforce HTTPS without hardcoding the language prefix, letting your framework (this looks like a Symfony app from the .htaccess structure) handle language routing properly.
2. Verify the Base Path Detection
The rule that sets the BASE environment variable uses a regex to auto-detect the application's base path:
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$ RewriteRule ^(.*) - [E=BASE:%1]
If Google's indexed paths don't align with what this regex expects (e.g., they're root-level paths while your app lives under /es_ES/), this can misconfigure the BASE variable, leading to incorrect redirects.
Solution:
Instead of relying on auto-detection, manually set the BASE variable if your app is definitely hosted under /es_ES/:
SetEnv BASE /es_ES
Replace the existing auto-detection rules with this line to eliminate regex matching errors.
3. Clear Browser Cache (Critical for 301 Redirects)
Since you're using R=301 (permanent redirect), browsers cache this rule aggressively. If there was a previous incorrect redirect setup, your browser might still be using that old rule when clicking from Google.
Quick Test & Fix:
- Try accessing the site from a private/incognito window first—if it works, the issue is cached redirects.
- Clear your browser's cache and cookies for the domain.
- Temporary switch
R=301toR=302(temporary redirect) during testing to avoid permanent caching, then switch back once confirmed working.
4. Check Plesk's Built-in Redirect Rules
Plesk has its own redirect configuration that can conflict with .htaccess rules. It's possible there's an extra redirect set at the server level that's causing the loop back to Google.
How to Check:
- Log into your Plesk control panel.
- Navigate to your domain's management page.
- Go to Redirects and ensure there are no unexpected redirect rules targeting Google or misconfigured paths.
- Also verify your SSL/TLS settings are correct to avoid mixed-content issues that might trigger unexpected behavior.
Final Validation
After making changes, test the redirect chain using curl to see exactly what's happening:
curl -L -v http://srad.wtf/your-google-indexed-page-path
This will show you each redirect step, helping confirm there are no loops or incorrect destinations.
内容的提问来源于stack exchange,提问作者Victor York

