开发者

.htaccess Apache URL Rewrite for Wordpress - permanently pointing one domain to another

开发者 https://www.devze.com 2023-02-01 07:02 出处:网络
I am trying to point www.olddomain.com/whatever to www.newdomain.com/whatever (as well as without the www.), but the Wordpress permalinks are not staying intact. Please help!!

I am trying to point www.olddomain.com/whatever to www.newdomain.com/whatever (as well as without the www.), but the Wordpress permalinks are not staying intact. Please help!!

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTP_HOST} ^olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc]

RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc]
RewriteRule ^(.*)$ htt开发者_如何学Gop://www.newdomain.com/$1 [r=301,nc]

</IfModule>


I fixed it:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc,L]

RewriteCond %{HTTP_HOST} ^www.olddomain.com [nc]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [r=301,nc,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>


A much simpler solution. Change the .htaccess to just say:

RedirectMatch 301 /(.*) http://www.newdomain.com/$1


You will need to move this block:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

behind the redirects. It grabs everything and sends it to index.php.

0

精彩评论

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

关注公众号