英文:
How to write htaccess 301 redirect - need to remove some "?" in query string
问题
我无法为某些特定页面编写有效的301重定向代码。
我有一些带有字符串中的“?”的旧URL,例如:
/old-url?page=2
/old-url?added1&page=2
/old-url?page=3
因此,如果可能的话,我想将所有这些页面重定向到一个唯一的/new-page。
你能帮助我吗?
通常我使用以下代码:
RedirectPermanent /old-url https://www.new-url.tld
对于所有页面,这都有效,除了这些URL。
英文:
I can't write a working 301 redirect for some specific pages.
I have got old url with "?" in the string, like :
/old-url?page=2
/old-url?added1&page=2
/old-url?page=3
So, if it's possible, I would like to redirect all these pageto a unique /new-page.
Can you please help me ?
Usually I use the code:
RedirectPermanent /old-url https://www.new-url.tld
It is working fine for all pages, except for these url.
答案1
得分: 0
这可能是你在寻找的内容:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=2$ [OR]
RewriteCond %{QUERY_STRING} ^added1&page=2$ [OR]
RewriteCond %{QUERY_STRING} ^page=3$
RewriteRule ^/?old-url$ /new-page [R=301,L,QSD]
显然,重写模块需要加载并在HTTP服务器中的该位置处处于活动状态。
该实现将在中央HTTP服务器的主机配置(实施此类规则的首选位置)或分布式配置文件(".htaccess"),如果启用了该功能并且文件位于HTTP主机的DOCUMENT_ROOT中,同样有效。
根据回答的OP的评论而更新:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=\d+$ [OR]
RewriteCond %{QUERY_STRING} ^added1&page=\d+$ [OR]
RewriteCond %{QUERY_STRING} ^page=\d+$
RewriteRule ^/?livre-d-or/?$ /avis-dj-mariage-64 [R=301,L,QSD]
英文:
This probably is what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=2$ [OR]
RewriteCond %{QUERY_STRING} ^added1&page=2$ [OR]
RewriteCond %{QUERY_STRING} ^page=3$
RewriteRule ^/?old-url$ /new-page [R=301,L,QSD]
Obviously the rewriting module needs to be loaded and active for that location inside the http server.
That implementation will work likewise, in the central http server's host configuration (the preferred place to implement such rules) or also a distributed configuration file (".htaccess"), if that feature has been enabled and the file is located in the http hosts DOCUMENT_ROOT
.
Update motivated by the OPs comment to this answer:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^page=\d+$ [OR]
RewriteCond %{QUERY_STRING} ^added1&page=\d+$ [OR]
RewriteCond %{QUERY_STRING} ^page=\d+$
RewriteRule ^/?livre-d-or/?$ /avis-dj-mariage-64 [R=301,L,QSD]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论