WordPress .htaccess www。不强迫

发布于 2024-12-12 14:40:40 字数 755 浏览 0 评论 0原文

我正在尝试强迫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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

天冷不及心凉 2024-12-19 14:40:40

进入设置->一般的:
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 :)

疧_╮線 2024-12-19 14:40:40
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
野鹿林 2024-12-19 14:40:40

在 WordPress 安装的 .htaccess 中(在您的情况下为 /blog/),您可以在 # BEGIN WordPress 行上方添加以下代码,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/subdirectory\/$1" [R=301,L]
</IfModule>
## Redirect primary WordPress URL to WWW version

显然,将“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

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ "http\:\/\/www\.domain\.com\/subdirectory\/$1" [R=301,L]
</IfModule>
## Redirect primary WordPress URL to WWW version

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).

吃兔兔 2024-12-19 14:40:40

有适合您的选项:

  1. 使用 wp-config.php 添加:

    define('WP_HOME','http://www.domainname.com');
    定义('WP_SITEURL','http://www.domainname.com');

  2. 使用 wp-admin

登录您的 wp-admin
浏览至“设置”-> '一般的'
在“WordPress 地址(URL)”和“站点地址(URL)”下,将 www 添加到地址中,如下所示

Have Option for you:

  1. using wp-config.php add:

    define('WP_HOME','http://www.domainname.com');
    define('WP_SITEURL','http://www.domainname.com');

  2. 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文