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

如何通过.htaccess重写URL,实现网站URL的SEO友好化?

Fixing SEO-Friendly URLs with .htaccess for Your Freenom Domain

Hey there! Let’s get your dynamic URL (www.abc.com/?i=1) converted to something SEO-friendly using .htaccess—this is a super common fix, and I’ve walked plenty of users through it with Freenom-hosted sites. Here’s a step-by-step breakdown:

First, Confirm Prerequisites

Before diving in, make sure:

  • Your server uses Apache (since .htaccess is Apache-specific; Freenom’s typical free hosting uses Apache, but double-check if you’re unsure).
  • The mod_rewrite module is enabled (most Apache hosts have this on by default, but if not, you might need to reach out to Freenom support).
  • You have a .htaccess file in your site’s root directory (create one if it doesn’t exist, and ensure it has read/write permissions).

Step 1: Enable Rewriting & Set Base

Start your .htaccess file with these lines to turn on rewrite functionality and set the root directory as your base:

RewriteEngine On
RewriteBase /

Step 2: Choose Your SEO-Friendly URL Structure

You have two main options here—pick the one that fits your site’s needs:

Option 1: Numeric Path (e.g., /page/1)

This works great if you’re using numeric IDs for pages. We’ll do two key things: redirect the old dynamic URL to the new friendly one, and internally rewrite the friendly URL back to the dynamic one so your server can process it.

Add these rules to your .htaccess:

# Redirect old dynamic URL to SEO-friendly path (permanent 301 for SEO)
RewriteCond %{THE_REQUEST} ^GET\ /\?i=([0-9]+)\s [NC]
RewriteRule ^ /page/%1? [R=301,L]

# Internally rewrite friendly URL back to dynamic URL (users won't see this)
RewriteRule ^page/([0-9]+)$ /?i=$1 [L]
  • R=301: Tells search engines this is a permanent move, so they’ll transfer the old URL’s SEO weight to the new one.
  • L: Stops processing further rules once this one runs, avoiding redirect loops.
  • The ? at the end of the redirect rule removes the original query string from the URL.

Option 2: Semantic Path (e.g., /about)

If your i=1 corresponds to a specific page (like an About page), use semantic URLs—these are even better for SEO and user experience.

Add these rules instead:

# Redirect specific dynamic URLs to semantic paths
RewriteCond %{THE_REQUEST} ^GET\ /\?i=1\s [NC]
RewriteRule ^ /about? [R=301,L]
RewriteCond %{THE_REQUEST} ^GET\ /\?i=2\s [NC]
RewriteRule ^ /services? [R=301,L]
# Add more lines for other i values as needed

# Internally rewrite semantic paths back to dynamic URLs
RewriteRule ^about$ /?i=1 [L]
RewriteRule ^services$ /?i=2 [L]
# Match these to your redirect rules above

Step 3: Test Thoroughly

After saving your .htaccess file:

  1. Visit www.abc.com/?i=1—you should be automatically redirected to your new friendly URL (check your browser’s address bar and the network tab in dev tools to confirm it’s a 301 redirect).
  2. Visit the new friendly URL (e.g., /page/1 or /about)—it should load the same content as the old dynamic URL without any errors.
  3. Double-check for redirect loops (if you see a "too many redirects" error, tweak your rules—using %{THE_REQUEST} in the condition helps avoid this, as it targets the original browser request instead of internal rewrites).

Important Notes

  • Freenom Hosting Limitations: Some free Freenom plans might restrict .htaccess usage. If your rules don’t work, confirm with Freenom’s support that mod_rewrite and .htaccess are allowed on your plan.
  • Avoid Duplicate Content: Always use 301 redirects for old URLs—this prevents search engines from indexing both the old and new URLs as separate content, which can hurt your SEO.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:27:00