开发者

htaccess conflicting with wordpress htaccess

开发者 https://www.devze.com 2023-04-08 10:27 出处:网络
I have the following code in my htaccess file: RewriteEngine On RewriteCond %{HTTP_HOST} !^www.example.com$

I have the following code in my htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301]
# 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]
</IfModule>

# END WordPress

I avoid editing the automated code by Wordpress becaus开发者_如何学运维e the changes may be erased and I'll have to do it all again. I have another site running the first three lines of code and it's working perfectly to replace example.com for www.example.com. That's all I really need for this example.com site but still preserving the Wordpress properties.

The problem

example.com is not redirecting to www.example.com but instead displaying a 301 error.


I'm using the following lines in all my WordPress-Sites before the # BEGIN WordPress. This should solve your problem. The L (for last) is the solution

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


"I avoid editing the automated code by Wordpress because the changes may be erased and I'll have to do it all again."

You can avoid a WordPress installation from modifying its root .htaccess file.

Simply connect via FTP, or other means and chmod your WordPress root .htaccess file properties to 0444.


Where is the conflict? I can't see any conflict. WordPress only touches the lines after # BEGIN WordPress

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号