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 服务器在本地计算机上测试它。尽管当我点击 http://localhost/ wordpress/
我被重定向到 http://www.mysite.com/wordpress/
但对于其他 URL,我根本没有被重定向。例如,
我的 URL 中有这个 URL本地机器http://localhost/wordpress/2010/11/shadows/
和服务器上的 http://www.mysite.com/wordpress/2010/11/shadows/
> 但是当我点击这个 URL 时,我没有被重定向到实时服务器上受尊重的 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]
但没有成功。
Trying to set 301 redirect in .htaccess
file and here is what i am trying to do
RewriteEngine On
RewriteCond %{HTTP_HOST} ^http://localhost/wordpress/$ [OR]
RewriteCond %{HTTP_HOST} ^localhost/wordpress/$
RewriteRule (.*)$ http://www.mysite.com/wordpress/$1 [R=301,L]
I am testing this on my local machine using WAMPP server.Though when i hit http://localhost/wordpress/
i am getting redirected to http://www.mysite.com/wordpress/
but for other URL i am not getting redirected at all.for e.g
I have this URL in my local machine http://localhost/wordpress/2010/11/shadows/
and this at the server http://www.mysite.com/wordpress/2010/11/shadows/
but when i hit this URL i am not getting redirected to respected URL on the live server ,but i am being showed same page from local machine.
Working:
http://localhost/wordpress/
=> Redirected to:
http://www.mysite.com/wordpress/
Not working
http://localhost/wordpress/2010/11/shadows/
=> Redirected to:
http://www.mysite.com/wordpress/2010/11/shadows/
As clear from URL, I am trying to do this in Wordpress.
Here is complete .htaccess
file
# 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]
Can any one tell me whats wrong with the redirection entry? Thanks in advance
Update
I have even tried this option
Options +FollowSymLinks
RewriteEngine on
RewriteBase /wordpress/
RewriteRule ^(.*)$ http://www.mysite.com/wordpress/$1 [L,R=301]
Did not worked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
始终是您先于其他人(仅谈论 RewriteRules,伙计!:D)(而且您已经忘记了
QSA
指令)。因此,这是 RewriteRule 的“干净”版本:
如果它位于
.htaccess
文件中,则尝试不使用/
,如下所示:顺便说一句,这是许多人中的第一次年,找到一个“正在建设”页面真好!
请告诉我是否有效。
Always you first then the others (talking about RewriteRules only, man! :D ) (and you've forgotten the
QSA
directive).So here's the "clean" version of your RewriteRule:
If it's in a
.htaccess
file then try without the/
like this:By the way this is the first time in many years that a find an "under construction" page nice!
Please tell me if it works.
%{HTTP_HOST]
将包含类似localhost
或www.thecolorsofmysoul.com
的内容。所以你的条件永远不会匹配。并且重定向到外部域永远不会触发。
另外,前两条规则共同作用,将任何非文件/目录映射到
index.php
。http://localhost/wordpress/
的正则表达式匹配字符串为“”,因此模式“.
”将失败,并且将失败并使用您的“更新”进行重定向。 顺便说一句,尝试使用此基础,这应该位于
DOCROOT/.htaccess
中。相应的 WordPress 规则(不应在此重定向之上)是You don't need to Repeat the base in the target,并且否定先行断言消除了对第一个 index.php 规则的需要。
%{HTTP_HOST]
will contain something likelocalhost
orwww.thecolorsofmysoul.com
. So your conditions will never match.and the redirecting to the external domain will never fire.
Also the first two rule act in consort to map any non-file/directory to
index.php
.http://localhost/wordpress/
has a regexp match string of "" so will fail the pattern ".
" and will fail through and will redirect with your "update". TryBTW with this base this should be in
DOCROOT/.htaccess
. The corresponding Wordpress rules (which shouldn't be above this redirect) areYou don't need to repeat the base in the target and the negative lookahead assertion removes the need for the first index.php rule.