【问题标题】:Redirecting domain keeping the parameters with .htaccess使用 .htaccess 保留参数的重定向域
【发布时间】:2015-02-03 11:50:27
【问题描述】:

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

所以如果我去: 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

【问题讨论】:

  • 你能显示你当前的 .htaccess 吗?
  • 添加了完整的 htaccess anubhava

标签: .htaccess


【解决方案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 做了一些其他改进。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-23
    • 2020-08-15
    • 2013-09-26
    • 2012-06-08
    • 2012-09-23
    • 2016-04-22
    • 1970-01-01
    相关资源
    最近更新 更多