I have an issue to rewrite url which is like:
http://examplepage.com/news/?aid=n_557eb95ed07360.45147988
to
http://examplepage.com/some-other-name
but it needs to be only this url if parameter changes it should do nothing. I think the problem is the dot in the parameter?
My current .htaccess for this matter is like this:
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
Any help appreciated. Thanks.
Escape the dot with \\.
to match a literal dot, not "any character".
A .
means " match any character " in a regular expression, so
/^aid=n_557eb95ed07360.45147988$/
will match
aid=n_557eb95ed07360.45147988
aid=n_557eb95ed07360045147988
aid=n_557eb95ed07360145147988
aid=n_557eb95ed07360245147988
...
but
/^aid=n_557eb95ed07360\.45147988$/
will only match
aid=n_557eb95ed07360.45147988
Demo: Regex101
As Drakes said, adding an escape to the dot should do the trick.
RewriteCond %{QUERY_STRING} ^aid=n_557eb95ed07360\.45147988$
RewriteRule ^news/$ /some-other-url [NC,L]
Or, if aid
is going to be dynamic, then you can use:
RewriteCond %{QUERY_STRING} ^aid=(.*)$
And if you want to search for aid
is any part of the query:
RewriteCond %{QUERY_STRING} !(^|&)aid=(.*)$
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.