简体   繁体   中英

How to change my site from example.com to www.example.com

I know this is an obvious question for you guys, to get to the point, my site's URL is papayaleavestea.com

I googled for answers and have found in the htaccess file :

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

# END WordPress

does anyone know or explain those line of codes or tell me what can I do cause I'm not that great of a programmer(more like a beginner still). would still appreciate any advice or help i can get from you guys.

To change a wordpress base url from example.com to www . example.com (or vice-versa) is a bit more tricky than a simple .htaccess modification. The reason for this is that wordpress handles all pages and will redirect based on the path that is setup in the database.

The first thing you need to do to stop the redirection to www is open up the wp_options table in your wordpress database, and look for the the records where option_name is the following :

  • home
  • siteurl

And adjust the option_value accordingly.

After you have changed these (which should change the majority of the links and references to files/posts/etc), you should install a plugin to assist in bulk changes to the data as there may be posts which have not been updated (if you manually added a link inside a post, it will stay that way until you change it)

One good plugin that can help accomplish this is Velvet Blues Update Urls

If you have a theme that has custom fields, you may need to go through it's options and update any custom javascript, etc to reflect the change.

You can set ServerAlias in your virtual host conf. This works if you have the same content on different IP addresses or multiple domains on a single IP address.

/etc/apache2/sites-available/example.conf

<VirtualHost *:80>
    DocumentRoot /www/example
    ServerName www.example.com
    ServerAlias example.com
</VirtualHost>

Using .htaccess

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
1.Access phpMyAdmin via your Control Panel. ...
2.Click on the MySQL database for your WordPress blog. ...    http://www.papayaleavestea.com
3.Click on wp-options.
4.Click on Edit on the line for siteurl. ...
5. change siteurl (papayaleavestea.com) this to (http://www.papayaleavestea.com) same home url 

if not work comment for me 

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