htaccess的重定向动态URL

htaccess的重定向动态URL

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

问题描述

我想写一个htaccess的重定向,但它不能正常工作,因为我想它。我现在的(工作)htaccess的所有HTML页面用1个字符重定向到索引文件为:

I am trying to write a htaccess redirect, but it is not working as I want it to.My current (working) htaccess redirects all html pages with 1 character to the index file as:

RewriteRule ^([a-zA-Z0-9]).html$ index.php?letter=$1

所以a.html被重定向到index.php?信= A现在,我需要重定向页面a.html页= 2的index.php信= A和?页= 2基本上我希望重定向的URL,但留下的动态部分完好无损。以下所有的返回404:

So a.html gets redirected to index.php?letter=aNow I need to redirect the page a.html?page=2 to index.php?letter=a&page=2Basically I want to redirect the url, but leave the dynamic part intact.All of the following return a 404:

RewriteRule ^([a-zA-Z0-9]).html?page=([0-9]+) index.php?letter=$1&page=$2

RewriteRule ^([a-zA-Z0-9]).html?page=(.*) index.php?letter=$1&page=$2

RewriteCond %{QUERY_STRING} page=(.*)
RewriteRule ^([a-zA-Z0-9]).html(.*) index.php?letter=$1&page=%1

我觉得我很接近,但我似乎无法到达那里:/任何人都可以给我最后推?

I think I'm close, but I can't seem to get there :/could anyone give me the last push?

推荐答案

重写规则必须是

RewriteRule ^([a-zA-Z0-9])\.html$ index.php?letter=$1 [QSA,NC,L]

请注意该URL参数的不可以可在重写规则匹配。如果你只需要添加一个额外的URL参数,你可以这样做随着 [QSA] 标志,将采取追加原始URL参数为你的照顾。

Please, note that URL parameters are not available for matching within the RewriteRule. If you simply need to append an extra URL parameter you can do so along with the [QSA] flag which would take care of appending the original URL parameters for you.

请注意,需要转义 \之前 HTML 的点。为好。该 [L] 可确保改写停止,没有进一步的规则(如有以下)的应用。

Please, note that the dot before html needs to be escaped \. as well. The [L] makes sure that rewriting stops and no further rules (if any below) are applied.

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

08-26 10:57