0

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.

MartyX
  • 3
  • 1
  • possible duplicate of [.htaccess rewrite url with get parameter](http://stackoverflow.com/questions/22853076/htaccess-rewrite-url-with-get-parameter) – Bruce Jun 26 '15 at 10:38

2 Answers2

0

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

Drakes
  • 23,254
  • 3
  • 51
  • 94
  • No problem. You just wrote in your question "it needs to be **only** this url if parameter changes it should do nothing" – Drakes Jun 26 '15 at 11:32
0

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=(.*)$
x3ns
  • 500
  • 2
  • 10