在.htaccess Apache的重定向问题 [英] Apache Redirect problem in .htaccess

查看:94
本文介绍了在.htaccess Apache的重定向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个getring简单的重定向声明承担我的Godaddy帐户效应的问题。我在我的.htaccess文件下面的语句:

  RewriteEngine叙述在的RewriteCond%{HTTP_HOST} ^ $ www.mydomain.net [NC]
重写规则^(。*)$ http://mydomain.net/$1 [R = 301,L]的RewriteCond%{HTTP_HOST} ^ $ mydomain.net [NC]
重写规则^ /列表/ $ / [R = 301]的RewriteCond%{HTTP_HOST} ^ $ mydomain.net [NC]
重写规则^ /博客/ $ http://myotherdomain.net/ [R = 301]

第1重定向总是工作。第二和第三的人但是,切勿上班。我刚刚从服务器获取404。 Apache的日志不显示任何常用资料 - 只需404

任何想法,任何人?
您的帮助将大大AP preciated。
谢谢


解决方案

  

每目录重写

  当使用的.htaccess 重写引擎文件中的每个目录preFIX(这总是为特定的目录相同)自动删除的模式匹配和自动添加的替代已经完成了。

   - http://httpd.apache.org/docs/2.2/mod/ mod_rewrite.html#重写规则


于是见好就收领先斜线出的格局。

I am having problems getring a simple redirect statement to take effect on my Godaddy account. I have the following statements in my .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.mydomain.net$ [NC]
RewriteRule ^(.*)$ http://mydomain.net/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^mydomain.net$ [NC]
RewriteRule ^/lists/$ / [R=301]

RewriteCond %{HTTP_HOST} ^mydomain.net$ [NC]
RewriteRule ^/blog/$ http://myotherdomain.net/ [R=301]

The 1st redirect ALWAYS work. The 2nd and 3rd ones however, NEVER work. I just get a 404 from the server. The Apache logs do not reveal any useful infomation - just a 404.

Any ideas, anybody? Your help will be greatly appreciated. Thanks

解决方案

Per-directory Rewrites
When using the rewrite engine in .htaccess files the per-directory prefix (which always is the same for a specific directory) is automatically removed for the pattern matching and automatically added after the substitution has been done.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule

So just leave the leading slash out of the pattern.

这篇关于在.htaccess Apache的重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆