问题描述
我阅读了所有其他类似的问题,但是不知道如何设置它,所以我的旧页面重定向到了应该的位置.
I read all the other similar questions, but could not understand how to set it up so my old pages redirect where they should.
这是我的设置:
我的旧站点页面:
http://www.oldsite.com/blog/?p=1234
http://www.oldsite.com/blog/?p=432
http://www.oldsite.com/blog/?p=xxxx
http://www.oldsite.com/blog/?p=1234
http://www.oldsite.com/blog/?p=432
http://www.oldsite.com/blog/?p=xxxx
我想像这样重定向前两个:
I would like to redirect the first two like so:
http://www.oldsite.com/blog/?p=1234-> http://www.newsite.com/somewhere/on/mysite/
http://www.oldsite.com/blog/?p=432 -> http://www.newsite.com/somewhere/else/on/mysite/
http://www.oldsite.com/blog/?p=1234 -> http://www.newsite.com/somewhere/on/mysite/
http://www.oldsite.com/blog/?p=432 -> http://www.newsite.com/somewhere/else/on/mysite/
,然后将所有其他页面(123、321、567、999等)重定向到我的主页,如下所示:
http://www.oldsite.com/blog/?p= * **** -> http://www.newsite.com/
and have all other pages (123, 321, 567, 999, ...) redirect to my home page like so:
http://www.oldsite.com/blog/?p=***** -> http://www.newsite.com/
提前谢谢!
推荐答案
我尝试了@Jon Lin代码,但不适用于我的WordPress网站.我认为问题是我正在运行WordPress ...我应该包含我的.htaccess代码,但我不认为WP会成为问题...
I tried @Jon Lin code, but it did not work for my WordPress site. I think the problem was that I am running WordPress... I should have included my .htaccess code, but I was not thinking that WP would be the problem...
这是我要使其正常工作所要做的:因为它是WP站点,所以您需要将代码放在WP mod_rewrite中.这是重定向之前我的.htaccess文件:
Here is what I had to do in order to make it work:Because it is WP site you need to put the code in the WP mod_rewrite. Here is my .htaccess before the redirects:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
及之后:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/blog/$
RewriteCond %{QUERY_STRING} ^p=998$
RewriteRule . /some/where/over-there? [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
希望这将帮助其他运行WP并遇到相同问题的人!
Hope this will help other people running WP and having the same problem!
这篇关于.htaccess和301重定向(动态页面)wordpress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!