简体   繁体   中英

Redirect a WordPress subdomen from WWW to non-WWW

I want to redirect www.udemy1.make4u.eu to udemy1.make4u.eu, but it doesn't work. I get this error DNS_PROBE_FINISHED_NXDOMAIN . I use Cloudflare for my website. In .htaccess I have this

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

    RewriteCond %{HTTP_HOST} ^www.udemy1.make4u.eu [NC]
    RewriteRule ^(.*)$ https://udemy1.make4u.eu/$1 [L,R=301]

</IfModule>

# END WordPress

Can you help me?

Update

I have this, but it doens't work

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

 RewriteCond %{HTTP_HOST} ^www.udemy1.make4u.eu [NC]
 RewriteRule ^(.*)$ https://udemy1.make4u.eu/$1 [L,R=301]


</IfModule>

# END WordPress

The “L” in the brackets at the end of a line mean to stop processing rewrites after the current one. Thus your custom rewrite should probably go before the WordPress ones.

I also believe you need to escape the periods in the RewriteCond line:

RewriteCond %{HTTP_HOST} ^www\\.udemy1\\.make4u\\.eu [NC]

Personally I would move it entirely outside of the block created by WordPress itself so that WordPress doesn't overwrite it.

The error "DNS_PROBE_FINISHED_NXDOMAIN" is the code you get in Google Chrome when you're trying to connect to a domain that doesn't exist.

I just checked in my terminal:

$ host www.udemy1.make4u.eu
Host www.udemy1.make4u.eu not found: 3(NXDOMAIN)
$ host udemy1.make4u.eu
udemy1.make4u.eu has address 104.27.185.117
udemy1.make4u.eu has address 104.27.184.117

You need to update your DNS entries for your domain. It seems that one DOES exist for udemy1.make4u.eu but you are MISSING an entry for www.udemy1.make4u.eu .

I think this happens a lot. People assume that www. "just works" without configuring it, but it's no different than any other subdomain like ftp. or mail. etc.. (except that www. is more popular).

Follow the CloudFlare Support documentation for creating a CNAME and create your new www.udemy1 CNAME record. I met you could set the CNAME value for www.udemy1 to literally udemy1.make4u.eu and it would resolve just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM