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

如何将Bootstrap+PHP+MySQL双语网站默认跳转至/in目录

Hey there! Let's get your default domain redirect sorted so visitors land straight on your Indonesian language site. Below are three solid methods depending on your server setup:

1. Apache Server (using .htaccess)

This is the go-to for most shared hosting environments. Just create or edit the .htaccess file in your website's root directory and add these rules:

RewriteEngine On
# Prevent redirect loops by skipping requests already in en/in folders
RewriteCond %{REQUEST_URI} !^/(en|in)/
# Permanently redirect all root requests to /in
RewriteRule ^(.*)$ /in/$1 [R=301,L]

The 301 status code tells search engines this is a permanent redirect, which helps with SEO. And the condition ensures visitors who manually go to /en won't get bounced back.

2. Nginx Server Configuration

If you're running Nginx, head to your site's config file (usually located in /etc/nginx/sites-available/) and add this block inside your server section:

location / {
    if ($request_uri !~ ^/(en|in)/) {
        return 301 /in$request_uri;
    }
}

After saving the changes, restart Nginx to apply them:

sudo systemctl restart nginx
3. PHP Redirect (No Server Config Needed)

If you don't have access to server config files or prefer a PHP-based solution, create an index.php file in your root directory (or edit the existing one) with this code at the very top:

<?php
// Check if we're already in en or in directory
$currentPath = $_SERVER['REQUEST_URI'];
if (!preg_match('/^\/(en|in)\//', $currentPath)) {
    // Send permanent redirect to Indonesian site
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /in" . $currentPath);
    exit;
}
?>

This will kick in before any other Bootstrap/PHP code runs, ensuring visitors get redirected right away.

Quick Notes:

  • Always test after setting up: Visit your root domain, /en, and /in to make sure there are no infinite redirect loops.
  • The 301 redirect is important for SEO—it signals to search engines that /in is the default version of your site.
  • Your language switcher buttons will still work as expected since we're excluding /en and /in from the redirect rules.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 10:07:01