本文介绍了Apache的htaccess的301重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在浏览器的请求 /article.php?id=123
服务器重定向到 /条/ 123
在浏览器的请求 /条/ 123
在服务器内部重写为 /article.php?id=123
在服务器内部匹配和浏览器重定向到 /条/ 123
在浏览器的请求 /条/ 123
重复4。
Browser requests /article.php?id=123
Server redirects to /article/123
Browser requests /article/123
Server rewrites internally to /article.php?id=123
Server internally matches and redirects the browser to /article/123
Browser requests /article/123
repeat from 4.
我想从article.php重写URL?ID = 123条/ 123
我添加了以下规则,它工作正常
重写规则^文章/(.*)/article.php?id=$1 [PT]
我也想增加一个301重定向规则,让搜索引擎知道article.php?ID = 123应该移动到物品/ 123。我增加了以下规则,但似乎没有工作。
重写规则^ article.php?ID =(。*)$ /条/ $ 1 [R = 301,L]解决方案
您需要匹配反对的实际要求的,而不是URI,因为URI被其他规则重写:
的RewriteCond%{THE_REQUEST} ^ [AZ] {3,9} \ /article\.php\?id =([^ \] +) 重写规则^文章\ .PHP $ /条/%1? [R = 301,L]如果你不反对的实际要求相匹配,会发生重定向循环:
I want to rewrite url from article.php?id=123 to article/123
I added the following rule, it works fine
RewriteRule ^article/(.*) /article.php?id=$1 [PT]I also want to add a 301 redirect rule to let search engine know article.php?id=123 should move to article/123. I added the following rule but seems not working.
RewriteRule ^article.php?id=(.*)$ /article/$1 [R=301,L]解决方案
You need to match against the actual request and not the URI because the URI gets rewritten by other rules:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /article\.php\?id=([^\ ]+) RewriteRule ^article\.php$ /article/%1? [R=301,L]If you don't match against the actual request, a redirect loop will occur:
更多推荐
Apache的htaccess的301重定向
发布评论