Score:1

apache rewrite: how do I check for empty or not present query parameter?

cl flag

might be best explained with an example:

- If I enter either URLs in my brower 
  - www.myhost.com/my-page.html?year=
  - www.myhost.com/my-page.html

- I then want to get redirected to  www.my-2nd-host.com/current-year/my-page.html

Any ideas how it's done? Thank you.

Score:1
kz flag

You can do it like this using mod_rewrite:

RewriteEngine On
RewriteCond %{QUERY_STRING) !(^|&)year=[^&]+
RewriteRule ^/?my-page\.html$ https://www.my-2nd-host.com/current-year/my-page.html [R=302,L]

The regex (^|&)year=[^&]+ checks for the presence of the year URL parameter with a non-empty value. The ! prefix then negates the expression so it is successful when that URL param is either empty or not present at all.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.