WordPress .htaccess www。不强迫
我正在尝试强迫www。在我网站的所有页面上。 我将 WordPress 安装在我的主站点 (/blog) 上的一个文件夹中。在 /blog 文件夹中有一个 .htaccess 文件,其中包含以下内容:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
在站点的主目录中。我有一个 .htaccess 文件,其中包含以下内容:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sitename.com [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteRule ^blog/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /blog/index.php [L]
在 WordPress 中,为 www 设置了选项。的www。出现在每个页面上,除了当我直接访问 site.com/blog 地址时
I'm trying to force www. on all the pages of my site.
I have wordpress install in a folder on my main site (/blog). In the /blog folder there is an .htaccess file with the following:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
In the main dir of the site. I have a .htaccess file that has the follow:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.sitename.com [NC]
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]
RewriteRule ^blog/index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/(.*)$ /blog/index.php [L]
In wordpress is have the option set for www. The www. appears on every page except the when I go straight the the site.com/blog address
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
进入设置->一般的:
WordPress 地址 (URL)
站点地址 (URL)
将它们都设置为 www.yoursite.com(而不是 yoursite.com),wordpress 会自动将所有 url 设置为 www.yoursite.com,仅此而已。
如果这还不够,您无论如何都不应该编辑 .htaccess 文件,因为每当您保存或重新加载永久链接设置时,Wordpress 都会覆盖您的 .htaccess(某些插件也可能会这样做)。
如果您确实想重写 URL,则应使用 WP Rewrite (Codex) 进行操作,或者如果您想要更简单的方法,有一个很好的插件,名为 Redirection (Wordpress.org Plugin目录)。
在重定向插件中,您只需将选项设置为 *.mydomain.com/* 即可使用 301 重定向到 www.mydomain.com/*,只要您保持插件处于活动状态,这就会处理您的 htaccess。
希望这有帮助:)
Go Settings -> General:
WordPress Address (URL)
Site Address (URL)
And set both of them to www.yoursite.com (instead of yoursite.com), wordpress automagically takes care for setting all the urls to www.yoursite.com and that's it.
If that isn't enough, you shouldn't edit the .htaccess file anyway, because anytime you save or reload your permalink settings, Wordpress will overwrite your .htaccesss (some plugins may do that as well).
If you do want to rewrite your URL, you should do it with WP Rewrite (Codex), or if you want a little more simple approach, there is a good plugin for that called Redirection (Wordpress.org Plugin Directory).
In Redirection plugin you can just set the options to *.mydomain.com/* to redirect to www.mydomain.com/* with a 301, and that will take care of your htaccess as long as you keep the plugin active.
Hope this helps :)
在 WordPress 安装的 .htaccess 中(在您的情况下为 /blog/),您可以在
# BEGIN WordPress
行上方添加以下代码,显然,将“domain.com”替换为您的实际域name 和“subdirectory”为安装 WordPress 的子目录的名称。 (OP请求中的/blog/)。
In the .htaccess of the WordPress installation (/blog/ in your case), you can add the following code ABOVE the line that reads
# BEGIN WordPress
Obviously, replace "domain.com" with your actual domain name and "subdirectory" with the name of the subdirectory where WordPress is installed. (/blog/ in the OP's request).
有适合您的选项:
使用 wp-config.php 添加:
define('WP_HOME','http://www.domainname.com');
定义('WP_SITEURL','http://www.domainname.com');
使用 wp-admin
登录您的 wp-admin
浏览至“设置”-> '一般的'
在“WordPress 地址(URL)”和“站点地址(URL)”下,将 www 添加到地址中,如下所示
Have Option for you:
using wp-config.php add:
define('WP_HOME','http://www.domainname.com');
define('WP_SITEURL','http://www.domainname.com');
using wp-admin
Log into your wp-admin
Browse to ‘Settings’ -> ‘General’
Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below