2016-04-15 162 views
1

网站正在使用表达式引擎,试图使用下面的代码添加一些简单的301重定向;htaccess重定向将旧网址附加到新网址

Redirect 301 /contact-us/ http://www.website.co.uk/get-in-touch 

这是返回以下url;

http://www.website.co.uk/get-in-touch?contact-us 

我找不到为什么这样做,我也试过了;

RewriteRule ^/contact-us/$ http://www.website.co.uk/get-in-touch [R=301] 
RedirectMatch 301 ^/contact-us/?$ http://www.website.co.uk/get-in-touch 

两者都返回相同的结果,htaccess作为一个整体;

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Removes index.php from ExpressionEngine URLs 
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

    #enforce the www's 
    RewriteCond %{HTTP_HOST} !^$ 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteCond %{HTTPS}s ^on(s)| 
    RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

</IfModule> 

RewriteRule ^/contact-us/$ http://www.website.co.uk/get-in-touch [R=301] 
#RedirectMatch 301 ^/contact-us/?$ http://www.website.co.uk/get-in-touch 
#Redirect 301 /contact-us/ http://www.website.co.uk/get-in-touch 

回答

1

您的第一个RewriteRule似乎欺骗了您。

顺序中的简单开关应该修复它。我的一般经验法则是:首先外部重定向,其次重写内部。

所以你的情况:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # Redirect /contact-us to /get-in-touch 
    RewriteRule ^contact-us(/?)$ /get-in-touch [L,R=301] 

    # Removes index.php from ExpressionEngine URLs 
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php?/$1 [L] 

    #enforce the www's 
    RewriteCond %{HTTP_HOST} !^$ 
    RewriteCond %{HTTP_HOST} !^www\. [NC] 
    RewriteCond %{HTTPS}s ^on(s)| 
    RewriteRule^http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

</IfModule> 
+0

当尝试这个,小心打开浏览器的开发工具和禁用缓存,因为301个重定向缓存。 –

+1

感谢您的帮助,完美工作! –

相关问题