重定向域使用.htaccess保留参数

时间:2014-12-05 10:23:23

标签: .htaccess

我正在尝试将旧域名(a.com)重定向到新域名(b.com),并将参数保留在网址中。

所以,如果我去: www.a.com/page/parameters 应该重定向到 www.b.com/page/parameters

我尝试过一系列选项无济于事。

在所有这些内容中,如果我进入域名本身(www.a.com),它会成功重定向到新域名(www.b.com),但是当我转到特定页面时(www.a.com) / page)在这种情况下,旧域保持不变,显示404页面。

这些是我已经尝试过的解决方案:

选项1

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?exampleold\.ie$ 
RewriteRule (.*)$ http://www.examplenew.com/$1 [R=301,L]
</IfModule>

选项2

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exampleold\.ie$ [NC]
RewriteRule ^(.*)$ http://www.examplenew.com/$1 [R=301,L]   
</IfModule>

选项3

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exampleold.ie
RewriteRule ^(.*) http://www.examplenew.com/$1 [P] 
</IfModule>

选项4

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?exampleold\.ie$ [NC]
RewriteRule ^ http://www.examplenew.com%{REQUEST_URI} [R=301,L]
</IfModule>

该网站是在Wordpress中制作的

这是完整的.htaccess

suPHP_ConfigPath /var/sites/b/examplenew.com/public_html
# 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]

Redirect 301 /testimonial/ab-jan13/ http://www.examplenew.com/
Redirect 301 /homepage_slide/gopro-hero4/ http://www.examplenew.com/
Redirect 301 /product/gopro-hero3-black-edition-surf/ http://www.examplenew.com/
Redirect 301 /contactus.php http://www.examplenew.com/
Redirect 301 /news/mundaka/487 http://www.examplenew.com/blog/


RewriteCond %{HTTP_HOST} ^(www\.)?example1old\.ie$ [OR]
RewriteCond %{HTTP_HOST} ^www.example1old.ie$ [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example2old\.ie$ [OR]
RewriteCond %{HTTP_HOST} ^www.example2old.ie$
RewriteRule (.*)$ http://www.examplenew.com/$1 [R=301,L]

</IfModule>

# END WordPress
#Gzip 

<ifmodule mod_deflate.c>

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript

</ifmodule> 

#End Gzip

1 个答案:

答案 0 :(得分:1)

不要将mod_alias规则与mod_rewrite规则混合,并在WP规则之前保留重定向规则。

suPHP_ConfigPath /var/sites/b/examplenew.com/public_html
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^(testimonial/ab-jan13/|homepage_slide/gopro-hero4/|product/gopro-hero3-black-edition-surf/|contactus\.php|news/mundaka/487) http://www.examplenew.com/ [L,NC,R=302]

RewriteCond %{HTTP_HOST} ^(www\.)?example1old\.ie$ [NC,OR]
RewriteCond %{HTTP_HOST} ^(www\.)?example2old\.ie$ [NC]
RewriteRule ^ http://www.examplenew.com%{REQUEST_URI} [R=301,L]

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

</IfModule>

# END WordPress
#Gzip 

<ifmodule mod_deflate.c>

AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript text/javascript

</ifmodule>     
#End Gzip

我在htaccess

中做了一些其他改进
相关问题