htaccess的301重定向与参数的URL [英] htaccess 301 redirect for URL with parameter

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

问题描述

我在我的htaccess的文件,这需要一个URL像下面这样:www.example.com/Page.php?id=About,并把它变成www.example.com/about。唯一的问题是,旧的URL不能被重定向到新的网址,当我设在htaccess的重定向301重定向(我的理解是,因为你不应该传递参数基本重定向301S - 例如基本的重定向我的已经试过如下图)。

 重定向301 /Page.php?id=About http://www.example.com/about
 

美中不足的是,新的URL不一定只是去掉了电流id,并以小写版本替换。例如,我也想:

 重定向301 /Page.php?id=Example http://www.example.com/example-page
 

我想保持重写URL的当前功能,同时也希望将旧网址的任何访问重定向到新的(即更新谷歌索引)。参观www.example.com/Page.php?id=About目前仍然有效,但显示一个页面,没有内容。

 选项+了FollowSymLinks
RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d

重写规则^([A-ZA-Z0-9 \  - ] +)?/ $ Page.php ID = $ 1
重写规则^(〔一个 - 杂 -  Z0-9 \  - ] +)/([一 - 杂 -  Z0-9 \  - ] +)/ 1 $ Page.php的id = $&安培;?标签= $ 2
重写规则^(〔一个 - 杂 -  Z0-9 \  - ] +)/([一 - 杂 -  Z0-9 \  - ] +)/([一 - 杂 -  Z0-9 \  - ] +)?/ $页2标签= $&放大器; .PHP 1 ID = $&放?tabid = $ 3
 

如果添加此规则,以你的.htaccess它应该做的重定向的工作解决方案

。这将增加的?ID =关于对重定向到/左右。如果您在2.4.0版或更高版本上运行,你可以添加QSD标志重定向查询字符串的放弃。

 的RewriteCond%{QUERY_STRING} ^ n =约$
重写规则^ page.php /约[NC,R,L]
 

I have the following in my htaccess file, which takes a URL like: www.example.com/Page.php?id=About and turns it into www.example.com/about. The only issue is that the old URLs are not redirecting to the new URLs when I set up Redirect 301s in the htaccess (which I understand is because you're not supposed to pass parameters in basic Redirect 301s - example of basic Redirect that I've tried below).

Redirect 301 /Page.php?id=About http://www.example.com/about

The catch is that the new URLs don't necessarily just strip out the current id and replace it with a lowercase version. For example, I would also want to:

Redirect 301 /Page.php?id=Example http://www.example.com/example-page

I want to keep the current functionality of rewriting the URLs, but also want any visits to the old URLs to redirect to the new ones (i.e. to update Google index). Visiting www.example.com/Page.php?id=About at the moment still works but shows a page with no content.

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([a-zA-Z0-9\-]+)/?$ Page.php?id=$1
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ Page.php?id=$1&tab=$2
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ Page.php?id=$1&tab=$2&tabid=$3

解决方案

If you add this rule to your .htaccess it should do the work of the Redirect. It will add the ?id=About to the redirect to /about. If you are running on version 2.4.0 or later, you can add the QSD flag to discard of the query string in the redirect.

RewriteCond %{QUERY_STRING} ^id=About$
RewriteRule ^page.php /about [NC,R,L]

这篇关于htaccess的301重定向与参数的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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