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

如何实现WordPress同时通过frace65.com与yyan.ch/frace65访问?

Alright, let's walk through how to get your WordPress site accessible via both frace65.com and yyan.ch/frace65—this involves tweaking your web server config and adjusting WordPress settings to handle both URLs smoothly. Here's the step-by-step breakdown:

1. Configure Your Web Server (Nginx or Apache)

First, make sure your web server routes both URLs to the same WordPress directory (/path/to/your/server/frace65—replace this with your actual server path).

Nginx Setup

You'll need two server blocks (or update your existing yyan.ch block) to handle both domains:

Server Block for frace65.com

server {
    listen 80;
    listen [::]:80;
    server_name frace65.com www.frace65.com;

    root /path/to/your/server/frace65;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock; # Adjust your PHP-FPM socket path as needed
    }
}

Update yyan.ch Server Block for /frace65 Subpath

Add this location block inside your existing yyan.ch server config:

location /frace65 {
    alias /path/to/your/server/frace65;
    index index.php index.html index.htm;

    # Handle WordPress rewrite rules for the subpath
    try_files $uri $uri/ /frace65/index.php?$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $request_filename; # Critical for correct PHP execution in subpath
    }
}

Note: Use alias instead of root here because root would append /frace65 to the file path, which doesn't match your actual directory structure.

Apache Setup

First, ensure mod_rewrite is enabled (run a2enmod rewrite if not). Then configure two virtual hosts, or update your yyan.ch host to include the subpath rule.

Virtual Host for frace65.com

<VirtualHost *:80>
    ServerName frace65.com
    ServerAlias www.frace65.com
    DocumentRoot /path/to/your/server/frace65

    <Directory /path/to/your/server/frace65>
        AllowOverride All # Lets WordPress use .htaccess rewrite rules
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/frace65_error.log
    CustomLog ${APACHE_LOG_DIR}/frace65_access.log combined
</VirtualHost>

Update yyan.ch Virtual Host for /frace65 Subpath

Add an Alias and corresponding directory block to your yyan.ch config:

<VirtualHost *:80>
    ServerName yyan.ch
    ServerAlias www.yyan.ch
    DocumentRoot /path/to/your/server/main-site # Replace with your main yyan.ch site path (if any)

    # Map /frace65 to your WordPress directory
    Alias /frace65 /path/to/your/server/frace65

    <Directory /path/to/your/server/frace65>
        AllowOverride All
        Require all granted
        RewriteEngine On
        RewriteBase /frace65/
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /frace65/index.php [L]
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/yyan_error.log
    CustomLog ${APACHE_LOG_DIR}/yyan_access.log combined
</VirtualHost>
2. Update WordPress to Support Both URLs

WordPress defaults to a fixed site URL, so we need to make it dynamic based on how users access the site. Edit your wp-config.php file (in the frace65 directory) and add these lines above the /* That's all, stop editing! Happy publishing. */ comment:

// Dynamically set site URL based on incoming request
$protocol = is_ssl() ? 'https://' : 'http://';
$site_path = ($_SERVER['HTTP_HOST'] === 'frace65.com' || $_SERVER['HTTP_HOST'] === 'www.frace65.com') ? '' : '/frace65';

define('WP_SITEURL', $protocol . $_SERVER['HTTP_HOST'] . $site_path);
define('WP_HOME', $protocol . $_SERVER['HTTP_HOST'] . $site_path);

This tells WordPress to use the correct URL (either frace65.com or yyan.ch/frace65) depending on how the user arrives.

Next, update your permalinks to ensure rewrite rules work for both paths:

  • Log into your WordPress admin dashboard
  • Go to Settings > Permalinks
  • Select your preferred permalink structure (e.g., "Post name")
  • Click Save Changes (this regenerates the rewrite rules)

If you already have content on your site, you might have absolute links pointing to one of the two URLs. You'll need to update these to work with both paths:

Run these commands (test first with --dry-run to avoid mistakes):

# Test replacing frace65.com links with yyan.ch/frace65 (reverse if needed)
wp search-replace 'http://frace65.com' 'http://yyan.ch/frace65' --dry-run

# If the test looks good, run without --dry-run
wp search-replace 'http://frace65.com' 'http://yyan.ch/frace65'

Note: If you're using HTTPS, replace http:// with https://.

Option 2: Use a Plugin

If you don't have WP CLI access, install the Better Search Replace plugin (from the WordPress repo) to safely update links in your database.

4. Test Both Access Methods
  • Visit frace65.com and check that pages, posts, media, and admin panel load correctly.
  • Visit yyan.ch/frace65 and do the same—verify no 404 errors, broken images, or CSS/JS issues.
  • Clear your browser cache if you see broken assets, as old cached URLs might cause problems.
5. Optional: Enable HTTPS

If you want to use HTTPS for both URLs:

  1. Install SSL certificates for both frace65.com and yyan.ch (e.g., via Let's Encrypt).
  2. Update your web server configs to listen on port 443 with SSL settings.
  3. Add this line to wp-config.php to force HTTPS for the admin area:
    define('FORCE_SSL_ADMIN', true);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 03:52:28