2012-02-14 32 views
-1

试图设置301重定向在.htaccess文件,这里就是我试图做301重定向是无法正常运行

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR] 
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ 
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L] 

我使用WAMPP server.Though我的本地机器上测试这个时候我打http://localhost/wordpress/我得到重定向到http://www.mysite.com/wordpress/但对于其他网址,我没有得到在all.for如重定向

我在我的本地机器http://localhost/wordpress/2010/11/shadows/这个URL,这在服务器http://www.mysite.com/wordpress/2010/11/shadows/但是当我打这个网址我没有得到重定向到实时服务器上受尊重的URL,但我显示的是相同的来自本地机器的页面。

工作

http://localhost/wordpress/ 
=> Redirected to: 
http://www.mysite.com/wordpress/ 

不工作

http://localhost/wordpress/2010/11/shadows/ 
=> Redirected to: 
http://www.mysite.com/wordpress/2010/11/shadows/ 

从URL作为清楚,我想这样做的WordPress的。 下面是完整的.htaccess文件

# BEGIN WordPress 
<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /wordpress/ 
RewriteRule ^index\.php$ - [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /wordpress/index.php [L] 
</IfModule> 

# END WordPress 

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR] 
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ 
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L] 

任何一个可以告诉我什么是错的重定向进入?在此先感谢

更新 我甚至试过这个选项

Options +FollowSymLinks 
RewriteEngine on 
RewriteBase /wordpress/ 
RewriteRule ^(.*)$ http://www.mysite.com/wordpress/$1 [L,R=301] 

没有奏效。

+0

请您输入网址的来源,以及网址重定向应该是什么,如果它有效或不准确,我很乐意帮助您 – 2012-02-14 16:07:07

+0

我不确定您的意思是网址来源和网址重定向。对不起,这个重写字段是新的 – 2012-02-14 16:10:37

+0

类似于“客户端类型'http:// localhost/wordpress /',应该被重定向到'http:// www.mysite.com/wordpress /'=> ** works **” 。然后“客户端类型为'http:// localhost/wordpress/2010/11/shadows /'并且应该被重定向到'http:// www.mysite.com/wordpress/2010/11/shadows /'=> ** doesn不工作**“......等等。只是为了“清楚样品”。谢谢=) – 2012-02-14 16:16:50

回答

0

你总是先那么别人(谈论的RewriteRules 只有,男人!d)(和你忘了QSA指令)。

因此,这里是你的重写规则的 “干净” 版本:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # BEGIN My Own rewrite rules 
    RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR] 
    RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ 
    RewriteRule (.*) http://www.mysite.com/wordpress/$1 [QSA,R=301,L] 
    # END My Own rewrite rules 

    # BEGIN WordPress 
    RewriteBase /wordpress/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /wordpress/index.php [L] 
    # END WordPress 

</IfModule> 

如果它在一个.htaccess文件则没有/这样的尝试:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    # BEGIN My Own rewrite rules 
    RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR] 
    RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ 
    # Without the/after wordpress: 
    RewriteRule (.*) http://www.mysite.com/wordpress$1 [QSA,R=301,L] 
    # END My Own rewrite rules 

    # BEGIN WordPress 
    RewriteBase /wordpress/ 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /wordpress/index.php [L] 
    # END WordPress 

</IfModule> 

通过这是多年来第一次发现一个“正在建设中”的页面!


请告诉我它是否有效。

+0

感谢您的投入和着陆页评论。我昨天晚上检查了上面的代码(把我的重定向放在第一位),它工作正常) – 2012-02-15 10:12:21

+0

如果它帮助它是我的荣幸! – 2012-02-15 19:46:32

0

%{HTTP_HOST]将包含类似localhostwww.thecolorsofmysoul.com的东西。所以你的条件永远不会匹配。

RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR] 
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$ 

并且重定向到外部域永远不会触发。

此外,在驸马前两个规则的行为,以任何非文件/目录映射到index.phphttp://localhost/wordpress/有一个正则表达式匹配字符串“”,所以会失败模式“.”,并将通过失败并将重定向到您的“更新”。尝试

Options +FollowSymLinks 
RewriteEngine on 
RewriteBase /wordpress/ 

RewriteCond %{HTTP_HOST} =localhost 
RewriteRule ^.* http://www.thecolorsofmysoul.com/wordpress/$0 [L,R=301] 

顺便说一句,这个基地应该在DOCROOT/.htaccess。相应的WordPress的规则(这不应该是这个重定向以上)是

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

您不必重复基础目标和式断言消除了第一的index.php规则的需要。