简体   繁体   中英

Wordpress mod_rewrite rule. Stop redirecting from example.com to www.example.com

I need to add a rule to my .htaccess file. This mod_rewrite needs to prevent my site from going to www.example.com, but rather stay on the example.com URL.

Please help.

UPDATE::

Here is my code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.co.za$ [NC]
RewriteRule ^(.*)$ http://www.example.co.za/$1 [L,R=301]
RewriteBase /
RewriteRule ^index\.php$ - [L]
# uploaded ?les
RewriteRule ^([_0-9a-zA-Z-]+/)??les/(.+) wp-includes/ms-?les.php??le=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
</IfModule>
# END WordPress

This is my first time working with the .htaccess file

Add below rule in your .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]

Don't forget to change "example" in your own domain name.

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