htaccess的301重定向动态URL重定向、动态、htaccess、URL

由网友(倾一世丶等一人 .)分享简介:我提出我的网站的新域名。需要重定向页面从old-site.com/oldpage.php?id=X 到new-site.com/newpage-X (X为数字)为什么这个规则不起作用? RewriteEngine叙述上重写规则^ oldpage.php?ID =(。*)$ http://new-site.c...

我提出我的网站的新域名。需要重定向页面 从 old-site.com/oldpage.php?id=X 到 new-site.com/newpage-X (X为数字)

为什么这个规则不起作用?

  RewriteEngine叙述上
重写规则^ oldpage.php?ID =(。*)$ http://new-site.com/newpage-$1 [R = 301,L]
 

解决方案

的的 重写规则 并只在的 URL路径而不是网址查询。你需要使用的RewriteCond 指令来测试网址查询(%{QUERY_STRING} )。因此,尝试这条规则:

 的RewriteCond%{QUERY_STRING} ^(([^&放大器;] *放大器;)*)ID =([^&功放;] +)及?(。*)?$
重写规则^ oldpage  .PHP $ http://new.example.com/newpage-%3?%1%4 [L,R = 301]
 

这条规则也将preserve其他参数的查询。

301重定向是什么,301重定向怎么设置

I am moving my site to new domain. Need to redirect pages from old-site.com/oldpage.php?id=X to new-site.com/newpage-X (X is number)

Why this rule does not work?

RewriteEngine on
RewriteRule ^oldpage.php?id=(.*)$ http://new-site.com/newpage-$1 [R=301,L]

解决方案

The RewriteRule does only operate on the URL path and not the URL query. You need to use the RewriteCond directive to test the URL query (%{QUERY_STRING}). So try this rule:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)id=([^&]+)&?(.*)?$
RewriteRule ^oldpage.php$ http://new.example.com/newpage-%3?%1%4 [L,R=301]

This rule will also preserve other parameters in the query.

阅读全文

相关推荐

最新文章