.htaccess Apache URL Rewrite for Wordpress - perma

2019-08-01 10:25发布

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 ^(.*)$ http://www.newdomain.com/$1 [r=301,nc]

</IfModule>

3条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-01 10:36

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>
查看更多
叼着烟拽天下
3楼-- · 2019-08-01 10:40

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.

查看更多
欢心
4楼-- · 2019-08-01 10:54

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

RedirectMatch 301 /(.*) http://www.newdomain.com/$1
查看更多
登录 后发表回答