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

如何通过.htaccess将example.com:84重定向至主站首页example.com?

Redirect example.com:84 to Your Homepage via .htaccess

Hey there! Let's get that port 84 redirect sorted for you. Here's exactly how to make anyone visiting example.com:84 automatically land on your main example.com homepage using an .htaccess file:

Step 1: Confirm mod_rewrite is enabled

First, double-check that your Apache server has the mod_rewrite module turned on. Most shared hosting providers enable this by default, but if you run into issues, you can check your hosting control panel (like cPanel) or reach out to your host's support team to confirm.

Step 2: Add the rewrite rules to .htaccess

Create or edit the .htaccess file in your website's root directory (where your main index.html/index.php file lives) and add these lines:

RewriteEngine On

# Redirect port 84 traffic to the main domain
RewriteCond %{SERVER_PORT} ^84$
RewriteRule ^(.*)$ https://example.com/ [R=301,L]

Let's break down what each line does:

  • RewriteEngine On: This enables Apache's URL rewriting functionality—without this, none of the rules below will work.
  • RewriteCond %{SERVER_PORT} ^84$: This condition checks if the incoming request is using port 84. The ^ and $ ensure we're matching exactly port 84, not just any port that includes the number 84.
  • RewriteRule ^(.*)$ https://example.com/ [R=301,L]:
    • ^(.*)$ captures any path appended to example.com:84 (like /old-page). If you want to preserve that path on your main domain (e.g., send example.com:84/old-page to example.com/old-page), keep the $1 at the end: https://example.com/$1. If you want everyone to land strictly on the homepage, leave it as https://example.com/.
    • R=301: This marks the redirect as permanent, which is best for SEO (it tells search engines to update their indexes to the new URL). If you're testing and want a temporary redirect first, use R=302 instead, then switch to 301 once you confirm it works.
    • L: This stands for "last"—it tells Apache to stop processing any further rewrite rules once this one matches, preventing conflicts with other rules you might have.

Quick Notes:

  • Replace https://example.com with your actual domain (use http:// if you don't have an SSL certificate, but HTTPS is always recommended for security).
  • If you already have existing rules in your .htaccess, add these lines near the top—before any other rewrite rules that might take precedence.
  • Test it out by typing example.com:84 into your browser—you should be instantly redirected to your main homepage.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.28 09:43:14