[英]htaccess rewrite specific parameter with dot
我有一個重寫網址的問題,例如:
http://examplepage.com/news/?aid=n_557eb95ed07360.45147988
至
http://examplepage.com/some-other-name
但是,如果參數更改,則僅需使用此url,否則它什么也不做。 我認為問題是參數中的點?
我當前對此問題的.htaccess如下所示:
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
任何幫助表示贊賞。 謝謝。
用\\.
轉義點\\.
匹配文字點,而不是“任何字符”。
一.
表示在正則表達式中“ 匹配任何字符 ”,因此
/^aid=n_557eb95ed07360.45147988$/
將匹配
aid=n_557eb95ed07360.45147988
aid=n_557eb95ed07360045147988
aid=n_557eb95ed07360145147988
aid=n_557eb95ed07360245147988
...
但
/^aid=n_557eb95ed07360\.45147988$/
只會匹配
aid=n_557eb95ed07360.45147988
演示: Regex101
正如Drakes所說,在點上添加轉義符可以解決問題。
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360\.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
或者,如果aid
將是動態的,則可以使用:
RewriteCond %{QUERY_STRING} ^aid=(.*)$
如果要搜索aid
,則查詢的任何部分:
RewriteCond %{QUERY_STRING} !(^|&)aid=(.*)$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.