Apache 为两种类型的查询字符串URL创建重写条件

Apache 为两种类型的查询字符串URL创建重写条件,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我有两种类型的查询字符串URL,在htaccess文件中创建重写时遇到困难。第一个URL类型是/component/afcatrades/109165?view=profile。我需要删除查询字符串?view=profile,并将其重写为此URL类型,其中%1是配置文件ID。我提出了以下重写规则,但它不起作用。需要调整什么才能使其正常工作 RewriteCond %{REQUEST_URI} ^/([0-9]+)$ RewriteCond %{QUERY_STRING} ^view=profi

我有两种类型的查询字符串URL,在htaccess文件中创建重写时遇到困难。第一个URL类型是/component/afcatrades/109165?view=profile。我需要删除查询字符串?view=profile,并将其重写为此URL类型,其中%1是配置文件ID。我提出了以下重写规则,但它不起作用。需要调整什么才能使其正常工作

RewriteCond %{REQUEST_URI}  ^/([0-9]+)$
RewriteCond %{QUERY_STRING} ^view=profile$
RewriteRule ^(.*)$ http://www.afca.ab.ca/links/afca-trade-members/profile/%1 [L,R=301]
第二种URL类型是书店?page=shop.product\u details&flypage=flypage ask.tpl&product\u id=4410&category\u id=11。我需要删除查询字符串?page=shop.product\u details&flypage=flypage ask.tpl&product\u id=4410&category\u id=11,并将其重写为此URL类型,其中URL的最后一段是与类别\u id关联的书店类别。产品\u id可以是任何0-9值,无需连接到新网站上的特定产品。我只需要它重定向到产品的类别。我已经包括了我提出的重写规则,但它同样不起作用

RewriteCond %{QUERY_STRING} page=shop.product_details&flypage=flypage-ask.tpl&product_id=([0-9]+)$&category_id=11
RewriteRule ^(.*)$ http://www.afca.ab.ca/book-store/delmar-cengage-nelson-education? [R=301,L]
非常感谢您的帮助。谢谢。

这应该可以:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^view=profile$
RewriteCond %{REQUEST_URI}  ^/component/afcatrades/([0-9]+)
RewriteRule ^(.*)$ /links/afca-trade-members/profile/%1? [L,R=301]

RewriteCond %{REQUEST_URI}  ^/book-store
RewriteCond %{QUERY_STRING} page=shop.product_details&flypage=flypage-ask.tpl&product_id=([0-9]+)&category_id=11
RewriteRule ^(.*)$ /book-store/delmar-cengage-nelson-education? [R=301,L]
这应该起作用:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^view=profile$
RewriteCond %{REQUEST_URI}  ^/component/afcatrades/([0-9]+)
RewriteRule ^(.*)$ /links/afca-trade-members/profile/%1? [L,R=301]

RewriteCond %{REQUEST_URI}  ^/book-store
RewriteCond %{QUERY_STRING} page=shop.product_details&flypage=flypage-ask.tpl&product_id=([0-9]+)&category_id=11
RewriteRule ^(.*)$ /book-store/delmar-cengage-nelson-education? [R=301,L]

什么对你不起作用?@starkeen第一个URL被改写成这个,页面是空白的,这意味着有错误。第二个URL未被重写,它将从此URL加载此页面中的内容,该URL显示在浏览器地址栏中。什么对您不起作用?@starkeen第一个URL正在被重写到此URL,该页面为空,这意味着存在错误。第二个URL未被重写,它将从此URL加载此页面的内容,该URL显示在浏览器地址栏中。第一次重写显示在地址栏中。正如您所看到的,查询字符串没有被删除,配置文件也没有作为一个段添加到URL中。第二次重写也不会删除查询字符串。地址显示为而不是。奇怪的是,RewriteRule末尾的问号应该负责删除查询字符串(在我的测试服务器上也是如此)。您的apache版本是什么?服务器使用的是apache 2.2.22。重写工作正在进行中。它与配置文件具有相同的基本URL。正在重定向的URL为:<代码>重写条件%{QUERY_STRING}视图=列表重写规则^(.*)$http://www.afca.ab.ca/links/afca-trade-members? [R=301,L]第一次重写显示在地址栏中。正如您所看到的,查询字符串没有被删除,配置文件也没有作为一个段添加到URL中。第二次重写也不会删除查询字符串。地址显示为而不是。奇怪的是,RewriteRule末尾的问号应该负责删除查询字符串(在我的测试服务器上也是如此)。您的apache版本是什么?服务器使用的是apache 2.2.22。重写工作正在进行中。它与配置文件具有相同的基本URL。正在重定向的URL为:<代码>重写条件%{QUERY_STRING}视图=列表重写规则^(.*)$http://www.afca.ab.ca/links/afca-trade-members? [R=301,L]